Reading Different Signals Problems


tigerlibin

Recommended Posts

I am using UHF to transmit several signals, the monitor displays analog and digital signals as below.

Rx: \013

Rx: A00000132486553565535655356553565535655356553565535655356553565535655356553565

535655356553565535655356553565535655356553565535655356553565535655356553565535

655356553565535655356553565535655356553565535655356553565535655356553565535655

356553565535655356553565535655356553565535655356553565535655356553565535655356

553565535655356553565535655271228765535655356553565007655350460765535012796534

400048005126553565535655356553565535655356553565535655356553565535655356553565

535655356553565535655356553565535655356553565535655356553565535655356553565535

655356553565535655356553565535655356553565535655356553565535655356553565535655

35655356553565535D11111111111111111111111111111111111111111111111111111111111111111111

111111111111111111111111111111111111111111111111111111111111

I set up a new protocol as below.

private string strIn = Read (1)

if (strIn =="A")

private string DataIn = Read(15)

myChannel.AddValue(DataIn)

Endif

In this case I can sucessfully read the first 15 number which is 000001324865535. However, this 15 numbers should be three signals so that each signal should be five numbers like, 00000 13248 65535. Can anybody tell me how can I parse these 15 numbers and arrange them to three channels for outputs, based on my code.

Many Thanks in advance.

Link to comment
Share on other sites

Thanks Guru for your help.

1. I tried to add your code into my system, the "left" and "right" ones are working ok, however the "mid" code is not working. Could you please advise me why and how can I improve it ?

2. If I would like to improve the system a bit further, such as, I would like to read 5 signals, so that 25 numbers should be read into "datain". After that what can I do to spilt them into 5 channels? I do not think "left, mid and right" will work.

Many Thanks.

Link to comment
Share on other sites

Hi Guru,

I actually got another two questions. Hopefully, I can still get some advice from you.

1. I can now run the code no problem. But after running several minutes it always tells me " C1136 Timeout: Line 4", and line 4 in my case is "private string DataIn = Read(15)"

2. The number displayed is possibly the ASCII number, I would like to convert it into the actual voltage measured. I tried to config it in the variable value properties, for example, in expression I wrote down "Channel1[0]*10", but this is not working. Can you please advise me how can I work this out.

Many Thanks

Link to comment
Share on other sites

1) That is because DF is trying to read faster than your device is spitting out, or your device is outputting an 'A' and then nothing else (or at least not 15 more characters) within the timeout specified for the port.

2) inside your addvalue(), add StrToDouble(), so for example:

channel1.addValue(strToDouble(left(datain,5)))

You may have to clear history on the channel after you do this to clear out the string values already there.

Link to comment
Share on other sites

Thanks a lot. It is now working after adding strToDouble.

1. However, even though I did not clear history on the channel, the system is still working fine. So is that necessary to clear history on the channel and what syntax should I add to clear history ?

2. Is there any way to solve the Timeout problem, it is still there after running several minutes.

Link to comment
Share on other sites

ClearHistory isn't required, especially if you restart. There was a possibility you might need it just the first time you made the change because the channel was used to expecting strings, but if you save and restart that would clear out the channel anyway.

The timeout is on the device side. Try and keep the monitor open and see what is happening. It seems you are getting "A" and then not getting 15 more characters within whatever your port timeout setting is (1 second?)

Link to comment
Share on other sites

Archived

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