Results 1 to 7 of 7

Thread: Serial plugin -- how to detect text message on port?

  1. #1
    Join Date
    Aug 2003
    Location
    Pacific Northwest
    Posts
    744

    Default Serial plugin -- how to detect text message on port?

    I have a device connected to the serial port that sends message text data on occassion. What I'd like to do is have girder detect incoming activity on the serial port and capture the data, so that I can then use an OSD plug-in to display the data on the screen. I.e., can the serial plug-in be used to detect as an event incoming message text data on the serial port, and capture that data.

    Although I know how to use the serial port plug-in to send data to a device on the serial port, and am aware of the switches plug-in that detects as an event the pressing (or unpressing) of a switch connected to two leads on the serial port, I'm not sure how to detect as an event incoming data on the serial port.

    Thanks!!!

    - Mike.

  2. #2
    Join Date
    Sep 2002
    Location
    Davis, CA, USA
    Posts
    382

    Default

    You need to configure a script to accumulate incoming data.

    From the Plugins | Settings for Generic Serial, choose your Serial Device

    Then Look at Message Definitions | Receive

    I have one that has Enable, Fixed Length, 1 Character, Translate Bin->Hex, Define Script

    I use the Lua variable DSSLastResponse to accumulate the incoming data and then use the TriggerEvent to trigger the OSD when the combo of current commmand and correct string length is valid.

    with the following script
    Code:
    -- Channel
    if DSSLastCommand == "FA07" then
         DSSLastResponse = DSSLastResponse .. SerialValue
         if strlen(DSSLastResponse) == 8 then
    -- 00CC hex should be 204 decimal
            DSSChannel = format ("%d", tonumber(strsub(DSSLastResponse,3,6), 16))
            TriggerEvent("DSSOSD",203,"Channel", DSSChannel)
         end
    
    -- Strength
    elseif DSSLastCommand == "FA10" then
         DSSLastResponse = DSSLastResponse .. SerialValue
         if strlen(DSSLastResponse) == 6 then
    -- 58 hex should be 88 decimal
            DSSStrength = format ("%d", tonumber(strsub(DSSLastResponse,3,4), 16))
            TriggerEvent("DSSOSD",203,"Strength", DSSStrength)
            DSSLastResponse = ""
         end
    
    -- DateTime
    elseif DSSLastCommand == "FA11" then
         DSSLastResponse = DSSLastResponse .. SerialValue
         if strlen(DSSLastResponse) == 18 then
    --s = CLng("&H" & Mid(LastResponse, 5, 2)) & "/" & _
    --CLng("&H" & Mid(LastResponse, 7, 2)) & "/" & _
    --Year(Now) & " " & _
    --CLng("&H" & Mid(LastResponse, 9, 2)) & ":" & _
    --CLng("&H" & Mid(LastResponse, 11, 2)) & ":" & _
    --CLng("&H" & Mid(LastResponse, 13, 2))
    --        DSSDateTime = format ("%s", strsub(DSSLastResponse,5,14))
            DSSDateTime = tonumber(strsub(DSSLastResponse,5,6), 16) .. "/"
            DSSDateTime = DSSDateTime .. tonumber(strsub(DSSLastResponse,7,8), 16) .. " "
            DSSDateTime = DSSDateTime .. format("%02d", tonumber(strsub(DSSLastResponse,9,10), 16)) .. ":"
            DSSDateTime = DSSDateTime .. format("%02d", tonumber(strsub(DSSLastResponse,11,12), 16)) .. ":"
            DSSDateTime = DSSDateTime .. format("%02d", tonumber(strsub(DSSLastResponse,13,14), 16))
            TriggerEvent("DSSOSD",203,"Time", DSSDateTime)
            DSSLastResponse = ""
         end
    
    -- Ignore everything else
    else
         DSSLastResponse = ""
    end
    The full GML file at http://www.girder.nl/serial.php?Link=471
    Jim Hughes

  3. #3
    Join Date
    Aug 2003
    Location
    Pacific Northwest
    Posts
    744

    Default

    I see! For TriggerEvent, I understand that the "DSSOSD" is the EventString, 203 is the device id -- but in your example, are "Strength" and DSSStrength parameters that are passed to your command?

  4. #4
    Join Date
    Sep 2002
    Location
    Davis, CA, USA
    Posts
    382

    Default

    Anything after the EventString and DeviceID are payload parameters.

    Payloads can be accessed in the triggered event as pld1 thru pldN

    In this case I use it to pass the info that I actually want the OSD command to display.

    i.e. for the OSD Popup, triggered by DSSOD, I use [pld1] [pld2] as the message text. Therefore pld1 = "Strength" and pld2 = the value of the LUA variable DSSStrength.
    Jim Hughes

  5. #5
    Join Date
    Aug 2003
    Location
    Pacific Northwest
    Posts
    744

    Default

    Very cool! I'll test all this out now! :P

  6. #6
    Join Date
    Aug 2003
    Location
    Pacific Northwest
    Posts
    744

    Default

    Jim, if you don't mind, one more question -- you said that you are using the Lua variable DSSLastResponse to accumulate the incoming data. How do you specify this? It appears to be in the line

    DSSLastResponse = DSSLast Response . . SerialValue

    Is SerialValue always the incoming data? What if I have a string of X characters?

    Thanks!

  7. #7
    Join Date
    Aug 2003
    Location
    Pacific Northwest
    Posts
    744

    Default

    Jim, never mind -- I answered my own question! I should have read the help files for serial.dll after I originally received your question! ops:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •