Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Callback GatherEventHandler ProcessDeviceMessage(GatherEventArgs Args)
- {
- STRING sComportMsg[100];
- IF( Args.RESULTS = 0)
- {
- sComportMsg = Args.RXSTRING;
- if((left(sComportMsg, 3) = "ran") || (left(sComportMsg, 3) = "run"))
- {
- if(issignaldefined(To_Scripts_Modules$))
- {
- To_Scripts_Modules$ = sComportMsg;
- sComportMsg = "";
- }
- }
- else
- {
- iPointer1 = find("\x22", sComportMsg) + 1; //All references to siPointer1 were proceeded by a '+ 1' so let's just add it once here
- iPointer2 = find("\x22", sComportMsg, iPointer1);
- while ((iPointer2 > iPointer1) && (byte(sComportMsg, (iPointer2 - 1)) = '\\'))
- { //If the character preceeding the " is a backslash, it's still part of the name so keep going till we find an unescaped "
- iPointer2 = find("\x22", sComportMsg, iPointer2 + 1);
- }
- if ((iPointer2 > 0) && (mid(sComportMsg, iPointer2, 3) = "\x22\x20\x22")) //If we find this sequence then we're dealing with crosspoint feedback which has two virtual names
- {
- iPointer2 = find("\x22", sComportMsg, iPointer2 + 3); //Don't start looking until after the " which preceeds the second virtual name in the crosspoint feedback
- while ((iPointer2 > iPointer1) && (byte(sComportMsg, (iPointer2 - 1)) = '\\'))
- { //If the character preceeding the " is a backslash, it's still part of the name so keep going till we find an unescaped "
- iPointer2 = find("\x22", sComportMsg, iPointer2 + 1);
- }
- }
- if((iPointer1 > 1) && (iPointer2 > iPointer1)) //If we don't find closing double quotes, don't bother proceeding
- {
- sTempName = mid(sComportMsg, iPointer1, iPointer2 - iPointer1);
- for(b = 1 to iNumOutputs)
- {
- if (sBufferName[b] = sTempName)
- {
- if(issignaldefined(To_Modules$[b]))
- {
- To_Modules$[b] = sComportMsg;
- sComportMsg = "";
- }
- break;
- }
- }
- }
- else
- {
- //Stuff like "pong" and "error:" responses could be handled here, if necessary
- }
- }
- RearmGatherAsync(Args.INPUT);
- }
- }
- THREADSAFE CHANGE From_Device$
- {
- while (1)
- {
- try
- {
- gatherasync("\x0D", From_Device$, ProcessDeviceMessage);
- }
- catch
- {
- print("3 Series issue with Comport message handeling\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement