Creating a new protocol


ethushara

Recommended Posts

Hi Admin,

I'm going to make a micro-controller module to use with my control system. And I need to develop it to read and write its data through the scada system. It means through the DAQFactory. But to do this I need to make a new protocol to match with the micro controller system. Here I can send 3byte 8bit data array (device no\channel no\data word)to the PC in a once a second or whatever the period. This can be programmed in the micro-controller. But the issue is to read this array to determine the device no, channel no and the data word it is needed to make a sequence or a new protocol in the daqfactory.

(I have tested this system with the micro-controller and the PC. The data receiving and transmitting can be seen through "Monitor" in device configuration. But need to process through channels)

So please guide me on this to process further. If you have any other way for this or any new suggestion please explain here.

Thanks in advance.

Link to comment
Share on other sites

You'll probably just want to use a sequence to start. Its always easier in a sequence. If you then want to create a protocol so others can use it, then do it after testing with just a sequence. As to what to do, can you post a screenshot of the monitor window, ideally with "Display all ASCII chars as codes" checked as well as "Display time of tx/rx"

Link to comment
Share on other sites

Thanks for your quick reply.

A screen shot is attached here. in the program i have arranged to send one data array (01/11/12/13/14/15/16/17), one variable (48) and one word ("HELLOW") to send to the PC (RX from PC) one set after a second manner. and also i pressed manually to send one value (44) three times to the microcontroller (TX from the PC) which can be seen in the screen shot. As in this i can send data arrays or seperate values from the m. controller.

So please help me to make the protocol through this sequence and also please come back to me for any clarification with regard to this.

Thanks.

post-6682-1316155899_thumb.jpg

Link to comment
Share on other sites

So I'm assuming you can make the protocol anything you want? If so, first decide if you want to send binary data at all, or if you'd rather just put everything in ASCII form (which tends to be easier, but not as efficient). If you go all binary, the trick is determining the frame, especially the end of frame. You can do fixed width, but that tends to be limiting. If you do variable width then you need something to mark the end of frame (and ideally the beginning). Typically this is /x02 and /x03, but you could choose whatever you wanted. The problem then is that you can't use those characters in the frame itself without doing some trick. For example, DF1 uses 10 as their end of line marker and to use it in the frame you have to put two of them to represent a single character (if I remember correctly, but you get the point). This makes it much more difficult to parse. My general recommendation is a frame like Modbus where the first character is say /x02 followed by a character that indicates the number of bytes remaining in the frame and optionally and end of frame marker, though that isn't really necessary if the frame size is provided.

Link to comment
Share on other sites

Thanks.

Actually i like to go under your recommendation. But please let me know how to use the character that indicates the number of bytes remaining in the frame

And I can make the frame such as the first character as /x02 and without including the no of bytes as anyway i use the end character as /x03 (x02/device no/channel no/data word*n/x03).

So please guide me to work on this (or on the first ex frame, using a character indicating the no of bytes) to make the sequence in the DAQ factory to read the data words in Rx frames verifying the device number and the channel no (through a channel) and write the data to the Tx frames as the same format.

I can do the arrangement in the micro controller to send and read the frames according to the above frame format.

Looking forward for a reply from you.

Thank you.

Link to comment
Share on other sites

If you use /x02.../x03 you'll pretty much be forced to use a fixed frame size and then you'll be limited down the road. I thus recommend the frame size method. So; /x02<length><data> where <length> is the number of bytes of <data>. In DAQFactory its then just:

device.mydevice.purge()
private string strIn = device.mydevice.read(2)
private string in = asca(strIn)
if (in[0] != 2)
   return // invalid frame, didn't start with 2
endif
strIn = device.mydevice.read(in[1])
in = asca(strIn)

That's the core part of it. You'll actually probably want a loop and a continue instead of return when there's an invalid frame. At the end, you'll have an array of bytes in the variable "in" which you can then process your data frame with. The array will not contain the header or length.

Link to comment
Share on other sites

Thanks.

If I'm right, as per your details I can receive the data through only one channel. But here I need to send no of data channels(20 - 30) to the PC. To do this should i have to repeat this by changing the variable name? But how can i send the exact data for the exact variable from the micro controller? And if i need to use more than one micro controller what will happened?

And if i suggest a frame like (/x02<length><device no><channel no><data>), is there any possibility to read the <data> separately from Daqfactory through a sequence through channels which are set according to the frame details(device # and the channel no).Then I can send the data(real time data as one set per a second)(one frame per one channel) from m. controllers by changing the device numbers and channel numbers and get the data to the daqfactory through separate channels configured according to the details of the frames.

looking forward for your kind explanation.

Thank you.

Link to comment
Share on other sites

Sorry, I'm trying to keep my replies general so they can be used in different applications. The code I provided will read in the frame with data. You can put whatever you want in the data, including device numbers, channel numbers and values for multiple values. Its all in the "in" variable at the end of that script. To push data into a channel from a sequence use the addvalue() function, either:

channelName.addvalue()

or

Channel.addvalue()

The first requires you know the channel name (6.9 in help). The second form will take numbers to describe the channel and only adds the value if the channel exists. See section 6.10 in the help for this one.

Link to comment
Share on other sites

Thanks a lot for your explanation. i tested as you said and finaly got the results. Now I can send my real time values of needed parameters and paly with them in Daqfactory. Now I need to edit the variable values in microcontroller from Daq factory.

I hope to do this i have to do the micro controller part first and then come back to you.

Thank you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.