Communicating Red Lion's Cub5V Meter With Pc Via Rs232


Minali

Recommended Posts

So far we have successfully by using command N5TA* communicated with Red Lion CUB5V counter interfacing through RS232. The result we got only one value at a time for next value we need to resend the command. We are actually looking for continuous result(value) as per the display of the counter.

We have created one sequence and wrote the following program their:

private string data

while(1)

try

device.myDevice.purge()

device.myDevice.write("*N5TA")

data = device.myDevice.readUntil(10)

myChannel.addValue(strToDouble(mid(data, 6,100)))

catch()

? strLastError

endcatch

delay(1)

endwhile

Also we create Channel named RS232 , Device Type-CUB5V, Device No = 2, Ch = 0, Timing = 0.

So please Guide us regarding this.

I have attached Cub5V manual and com Pdf.

Thank you.

Cub 5V Manual.pdf

CUB5COM.pdf

Link to comment
Share on other sites

By Doing the setting told to you we get this in channel table:

Row

Value

0

-1

And when we compile sequence we didn't get anything but when we click the Begin option in sequence summary we get error in command/Alert window as : C1000 Channel or function not found: Test Line 7

Link to comment
Share on other sites

You need to change "myChannel" in the script to whatever you named your channel, "RS232" perhaps?

Yes, you need a while loop if you want it to continuously query the input channel. There are other ways to set this up, but this is the quickest to debug.

Link to comment
Share on other sites

I have done the successfully communication between cub5v and DAQ factory.but now I need to communicate more than one devices .I have created different channel as per number of devices and also created the sequences .but only one device is communicating at a time .so, Please guide me .

Thank you

Link to comment
Share on other sites

OK, four isn't too bad. I would just add the code into this sequence. You could just copy and paste, but it'd be better form to create a separate sequence function that handles the I/O. Lets call it readCUB:


function readCUB(id, string chanName)


private string data
try
device.myDevice.purge()
device.myDevice.write("*N" + doubletostr(id) + "TA")
data = device.myDevice.readUntil(10)
execute(chanName + ".addValue(strToDouble(mid(data, 6,100)))")
catch()
? strLastError
endcatch


[/CODE]

Then in your main sequence, change it to:

[CODE]

while(1)
readCub(5, "myChannel")
delay(0.1)
readCub(6, "myOtherChannel")
delay(0.1)
readCub(7, "myOtherChannel7")

delay(0.1)
readCub(8, "myOtherChannel8")
delay(1)
endwhile


[/CODE]

Change the above to whatever id's and channel names you want to use. I added a 0.1 second delay between devices because often RS485 device transievers aren't as fast as DAQFactory. This gives them a chance to switch off before DF sends the next query to the next device.

Note that I haven't added any protection code, so you should only call readCUB, or for that matter do anything on that serial port from within the while() loop sequence. If you try and do it from another sequence at the same time, you'll likely run into conflicts. You'd have to add lockPort() calls to protect the communications frame otherwise.

Link to comment
Share on other sites

Dear sir ,

1.Can i generate the shotcut key in DAQfactory? Which used for upload the setpoint 2 of cub5v .Cub5v have command (such as N2DV25*) to change the value of setpoint 2.

2.Can i connect the more device on single RS232 without using RS232 to RS485 converter .

Link to comment
Share on other sites

1. Yes, but I typically recommend against it, at least if the key directly affects the output. This is because accidentally pressing a key is a rather easy thing to do. However, if you were to have the key popup a window asking for confirmation or the output value, it would probably be safer. Either way, to do it use the OnChar system event. Basically, create a sequence called "OnChar" and in it, check the "char" local variable. For example:


if (char == "a")
output = 2
endif

[/CODE]

See section 5.28 in the help for more details on this and other system events.

2. No, although I have seen a device that was able to do multidrop on RS232, it is not supported by the transport layer, nor is it supported by 99.99999% of devices out there. So, unless the documentation in your hardware says it can do multidrop with RS232 and shows you how to wire it, you should stick with 485, or consider buying a multiport RS232 device and plugging each hardware device into its own port.

Link to comment
Share on other sites

Hello Guru,

I m successful in communication between PC & CUB5V. Also we get logging data in Excel as per the display of counter,but I want only the increasing values on display in the excel sheet and ignores the decreasing one. Also besides Time & value i want one extra column for the approx maximum value where counter stops like shown below:

Time

Counter Value

Approx Max Value

0.19

0.199

0.2

0.99

1

1.2

1.3

1.4

1.5

1.7

1.8

1.99

2

2

2.1

2.2

2.3

2.4

……

3

3

SUM(2,3) 5

Suggest me the desired changes i need to do in logging setting.

Thank U in Advance.

Link to comment
Share on other sites

I am successful in communication between PC & CUB5V. Also we get logging data in Excel as per the display of counter,but I want only the maximum values on display in the excel sheet and ignores the decreasing one and increasing value . Also besides Date &Time i want one column for the maximum value (setpoint2) where counter stops.Please find attached pdf file.

data2.pdf

Link to comment
Share on other sites

Logging sets will log all values. To log selected values, you either need to create separate channels to hold only the values you want logged and set the logging set to use those channels instead of your main input channels. Or, you can use an export set triggered at the end of your polling loop whenever you want to log a line of data. Of course you can also just use lower level File. functions in the same way.

Link to comment
Share on other sites

Sir, If I want the Channel Table should read only particular value (i.e. setpoint (E) in my case), Is the following program code Correct?

private string data

while(1)

try

device.CUB5V.purge()

if(device.CUB5V.Read(N0TA=>N0TE))

Return

device.CUB5V.write("N0TA*")

data = device.CUB5V.readUntil(10)

Counter.addValue(strToDouble(mid(data, 6,100)))

catch()

? strLastError

endcatch

delay(1)

endif

endwhile

Link to comment
Share on other sites

No. That if() line you wrote doesn't really make sense, not to mention none of the code after the Return and before the endif will ever execute. I think you more likely want something like:


private string data
private ndata
while(1)
try
device.CUB5V.purge()

device.CUB5V.write("N0TA*")
data = device.CUB5V.readUntil(10)
ndata = strToDouble(mid(data,6,100))
if (ndata > counter[0])
Counter.addValue(ndata)
endif
catch()
? strLastError
endcatch
delay(1)
endwhile
[/CODE]

This will only add a new counter value if the reading is greater than the last counter value. Note that you'll have to initialize counter to something when DF starts unless you are using persist. For example, to initialize to 0, do:

counter.addValue(0)

You might put that at the top of the sequence, before the while(1)

Link to comment
Share on other sites

Hello Guru,

I have one query regarding the code written below:

private string data

while(1)

try

device.CUB5V.purge()

device.CUB5V.write("N0TA*")

data = device.CUB5V.readUntil(10)

if ("N0TA*">="N0TE*")

Counter.addValue(strToDouble(mid(data, 10,200)))

delay()

endif

catch()

? strLastError

endcatch

delay(1)

endwhile

The above code runs well & doesn't leave any error but the result we get in Channel Table is not according to the 'if condition' specified in above code.

"N0TA" command is to read display input of CUB5V & "N0TE" for reading setpoint 2 value of CUB5V

So please suggest some solution regarding.

Thanks in Advance.

Link to comment
Share on other sites

This line:

if ("N0TA*">="N0TE*")

is always false. You are comparing two static strings. It would be like writing:

if (3 >= 4)

You don't want to compare the string you are sending out the serial port. You want to compare the result. Where are you storing the setpoint from the N0TE command? If its in a variable, say one called "setpoint", you would change the are around the if() to:

private nData = strToDouble(mid(data,10,200))

if (nData >= setpoint)

counter.addValue(nData)

endif

Also, you don't need the delay(). In fact, it will do nothing because you aren't including how long you want to delay.

Link to comment
Share on other sites

Hi Guru,

As told by you I made the changes in the code tell me if it is not correct :

private string data

while(1)

try

device.CUB5V.purge()

device.CUB5V.Write("N0TA*")

data = device.CUB5V.readUntil(10)

private nData = strToDouble(mid(data,6,200))

if(nData >= setpoint2)

counter.addValue(nData)

endif

catch()

? strLastError

endcatch

delay(1)

endwhile

Also have One query that In above Code there is a need to define setpoint2 , I tried but I didn't get any solution, so PLEASE help me regarding

Many Thanks in Advance

Link to comment
Share on other sites

With the following program we get the Result But in place of 10 we want the string for that if we write :

private string setpoint2 = Read("N0TE*") we get error as-C1086 One of the parameters was empty: Test Line 9

private string data

private setpoint2 = "10"

while(1)

try

device.CUB5V.purge()

device.CUB5V.Write("N0TA*")

data = device.CUB5V.readUntil(10)

private nData = strToDouble(mid(data,6,200))

if(nData >= setpoint2)

counter.addValue(nData)

endif

catch()

? strLastError

endcatch

delay(1)

endwhile

Suggest some solution

Link to comment
Share on other sites

  • 2 weeks later...

Archived

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