lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


 

Does anyone have a suggestion for parsing the data or even an existing project? Any and all input is welcome.

 

Thanks!

Russell

 

 

Russell,

I have been working on a “smart buffer” for just this issue, although it is not complete yet. However, it might give you some ideas on how to proceed. It is NOT pure Lua, but rather consists of two userdata object – the “smart buffer” and the serial port driver that takes the smart buffer as an argument.

 

The serial port driver simply reads and writes binary data from the smart buffer. Then in Lua, the application can read and write various sized variables from the smart buffer. For example, the library has the following functions/methods:

 

Sequential Access: (pushes to the TX buffer, pops from the RX buffer)

get_byte(), get_word(), put_word(value)

 

Random Access:

get_byte(offset), get_word(access), put_word(offset, value)

 

Of course, if you are writing a userdata library, it may be just as easy to fully decode the serial protocol in ‘C’ and use callbacks to Lua to process the data. In my experience, this may actually be a better approach for “structured” protocols such as those used for industrial automation (Modbus) or SCADA (DNP3).

 

Tim