Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. Callback GatherEventHandler ProcessDeviceMessage(GatherEventArgs Args)
  2. {
  3. STRING sComportMsg[100];
  4.  
  5. IF( Args.RESULTS = 0)
  6. {
  7.  
  8. sComportMsg = Args.RXSTRING;
  9.  
  10. if((left(sComportMsg, 3) = "ran") || (left(sComportMsg, 3) = "run"))
  11. {
  12. if(issignaldefined(To_Scripts_Modules$))
  13. {
  14. To_Scripts_Modules$ = sComportMsg;
  15. sComportMsg = "";
  16. }
  17. }
  18. else
  19. {
  20. iPointer1 = find("\x22", sComportMsg) + 1; //All references to siPointer1 were proceeded by a '+ 1' so let's just add it once here
  21. iPointer2 = find("\x22", sComportMsg, iPointer1);
  22.  
  23. while ((iPointer2 > iPointer1) && (byte(sComportMsg, (iPointer2 - 1)) = '\\'))
  24. { //If the character preceeding the " is a backslash, it's still part of the name so keep going till we find an unescaped "
  25. iPointer2 = find("\x22", sComportMsg, iPointer2 + 1);
  26. }
  27.  
  28. 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
  29. {
  30. iPointer2 = find("\x22", sComportMsg, iPointer2 + 3); //Don't start looking until after the " which preceeds the second virtual name in the crosspoint feedback
  31.  
  32. while ((iPointer2 > iPointer1) && (byte(sComportMsg, (iPointer2 - 1)) = '\\'))
  33. { //If the character preceeding the " is a backslash, it's still part of the name so keep going till we find an unescaped "
  34. iPointer2 = find("\x22", sComportMsg, iPointer2 + 1);
  35. }
  36. }
  37.  
  38. if((iPointer1 > 1) && (iPointer2 > iPointer1)) //If we don't find closing double quotes, don't bother proceeding
  39. {
  40. sTempName = mid(sComportMsg, iPointer1, iPointer2 - iPointer1);
  41.  
  42. for(b = 1 to iNumOutputs)
  43. {
  44. if (sBufferName[b] = sTempName)
  45. {
  46. if(issignaldefined(To_Modules$[b]))
  47. {
  48. To_Modules$[b] = sComportMsg;
  49. sComportMsg = "";
  50. }
  51. break;
  52. }
  53. }
  54. }
  55. else
  56. {
  57. //Stuff like "pong" and "error:" responses could be handled here, if necessary
  58. }
  59. }
  60. RearmGatherAsync(Args.INPUT);
  61. }
  62. }
  63.  
  64.  
  65. THREADSAFE CHANGE From_Device$
  66. {
  67. while (1)
  68. {
  69. try
  70. {
  71. gatherasync("\x0D", From_Device$, ProcessDeviceMessage);
  72. }
  73. catch
  74. {
  75. print("3 Series issue with Comport message handeling\n");
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement