Red Lion DSPSX Raw Serial Port

amitpanvekar

Member
Join Date
Jan 2013
Location
London
Posts
44
Hello Guys,

I got RS232 serial output from Navigational Device. I want to display that message on to vitual HMI using Read Lion DSPSX.

How do I create the database in Crimson 3 for the above application.I know about the predefined functions for raw serial Port such as PortRead,PortInput etc. However, don't know how to utilize those functions.

Thanks
 
Here's a tech note from Red Lion on the subject:
http://www.redlion.net/Support/TechNotes/HumanMachineInterface/TNOI22.pdf

It explains the setup but not the usage of the commands. I think the key point is in the middle of the last page: In the On Update action for the raw serial driver, you have to put a call to your program that contains the PortInput/PortRead functions.

I've done raw serial with the G3 before and found that it works well (once tech support set me straight on a few issues). I can post some of my old programs if you want.
 
Hi John,

I have followed each step written on that application note but i had no luck to get the output.

On Update: I am calling PortRead function to read the raw serial port output.

Cheers
Amit
 
I've attached an excerpt from the Crimson 2 manual that describes the use of the PortRead function. For some reason this explanation was not included with Crimson 3. Make sure you specify the correct port number... click on the port you're using in the Communications pane and the port number will be shown in the status bar at the bottom.

Are you sure all of the RS232 settings are correct?

What about the cable... purchased or homemade?
 
Thanks for your reply..

My serial output string in hex format is : 30 32 30 2e 30 31 35 74 0d 0a

I am using the home made cable. I have connected RS232's (from DSPSX000)
Red (TxD) to Serial out TxD
Green (GND) to Serial out GND
Yellow (RxD) to Serial out RxD

When I am using PuTTy (Serial emulator) to see the output from my device. I am able to see the output.

Please find the attached crimson database.

Cheers
 
Code:
cstring input;
int value;

for (;;)
{
    input := PortInput(2,'*',13,1000,50);
    if (value:= TextToInt(input,50))
    {
    speed:= value;
    PortPrint(2,"Value is ");
    PortPrint(2,IntToText(value,10,5));
    PortPrint(2,"\r\n");
    }
}
Some thoughts on your program:
1. Since you are running an infinite loop, you probably want to set the program to run in the background. Otherwise the G3 will lock up.
2. You are overcomplicating things by trying to read and write to the same port. I'd suggest just doing a read and displaying the result on the Data Station's virtual HMI. Don't worry about writing until you get the comms working right.
3. One thing I discovered with the PortInput command is that the Length parameter has to match the number of characters you receive. You can't just set it to a big number expecting to catch everything. I know that sounds strange and I don't recall all the details but you may want to try using PortRead initially.
4. Your cable description has Tx to Tx and Rx to Rx but I assume you have the transmit and receive lines swapped?
 
I don't know if it will help you but here is a raw serial program that I wrote for a G3 Kadet some time ago. This is communicating with a RS232 device that writes data to a USB flash drive. In this application, I always first send a command to the device, then wait for a response. The while(PortRead...) statement is a trick I learned from tech support. It clears out the serial buffer so you don't get any garbage characters during the PortInput.

I do remember that it took a lot of trial and error to get this set up correctly, but it has worked flawlessly ever since.


Code:
// CREATE & OPEN FILE FOR WRITING (HANDLE=1)
USBwriteAction := 1;
while(PortRead(4, 0) > -1) {}
PortPrint(4,"O 1W>" + MakeFilename() + "\r");
response := PortInput(4,0,0,1000,4);
if(response == ""){ USBwriteCode := 0xFF; return; }
USBwriteCode := TextToInt(Mid(response, 1, 2), 16);
if(USBwriteCode > 0) return;

// WRITE DATA TO FILE
for(i:=0; i<=24; i++){
    USBwriteAction := 0x10 + i;
    while(PortRead(4, 0) > -1) {}
    PortPrint(4,"W 1>" + IntToText(Len(USBwriteArray[i]),16,2) + "\r");
    response := PortInput(4,0,0,1000,4);
    if(response == ""){ USBwriteCode := 0xFF; return; }
    USBwriteCode := TextToInt(Mid(response, 1, 2), 16);
    if(USBwriteCode > 0) return;

    USBwriteAction := 0x30 + i;
    while(PortRead(4, 0) > -1) {}
    PortPrint(4,USBwriteArray[i]);
    response := PortInput(4,0,0,1000,14);
    if(response == ""){ USBwriteCode := 0xFF; return; }
    USBwriteCode := TextToInt(Mid(response, 11, 2), 16);
    if(USBwriteCode > 0) return;
}

// CLOSE FILE
USBwriteAction := 2;
while(PortRead(4, 0) > -1) {}
PortPrint(4,"C 1\r");
response := PortInput(4,0,0,1000,4);
if(response == ""){ USBwriteCode := 0xFF; return; }
USBwriteCode := TextToInt(Mid(response, 1, 2), 16);
if(USBwriteCode > 0) return;
 
cstring input;
int value;

for (;;)
{
input := PortInput(2,'*',13,1000,50);
if (value:= TextToInt(input,50))
{
speed:= value;
PortPrint(2,"Value is ");
PortPrint(2,IntToText(value,10,5));
PortPrint(2,"\r\n");
}
}

First I would get rid of the infinite loop. It should not be needed. Calling your program from the OnUpdate of the raw serial port should be sufficient. Second, you are are looking for a Starting Character of "*" which I did not see that you are sending from Putty. Lastly Start simple. Create a string tag (sTest in the example below), and move your input to there. try a program with the following.

cstring input;

input = portread(2,0,13,1000,50);
if (input == ""); Return; //Check for valid input if not exit program
sTest = input;

This will allow any start character, and read until <CR>. You can also try putting 0 in the length, which will read until <CR> regardless of length. If you are still having problems, check your cable. Swap the TX/RX wires on one side or use a null modem adapter. Also try sending a portprint with a test string to check your comms.

The support at Red Lion is excellent. Send them an email, and I'm sure they can get you set straight.
 
Thanks John.

I got it working but after converting string to integer type using TextToInt command.

How could I see the String on DSP's Virtual HMI. I can see the integer data on Online watch window.I also added the string data tag to see the original received string. But I could not able to see the String as a text on watch window.


I have changed the program as below

Code:
cstring input;
int value;

input := PortInput(2,0,13,1000,8);
speed2 := input;
if (value:= TextToInt(input,10))
{
    speed:= value;
}
Cheers
Amit
 
The virtual HMI in the Data Station is configured the same as a normal HMI. You can put Integer and/or String display primitives on the screen and associate them with data tags. In order to see the display, you have to enable the Ethernet port of the Data Station (set IP, subnet, etc) and turn on Remote Viewing in the Web Server. Then just connect your PC and put the IP into Internet Explorer.
 
Hi John,

I didn't get the String output on Virtual HMI. I have changed the String Tag options. I can see the TextToInt on display but don't know what wrong.

I have defined one String with name STRING2.

Code:
cstring input;
int value;

input := PortInput(2,0,13,1000,8);
STRING2 := input; //Assigning String to STRING2
if (value:= TextToInt(input,10))
{
    speed:= value;
}

Thanks
Cheers
Amit
 
The only thing that I'm thinking, is that you are sending 0d 0a and the PortInput is looking for 0d <CR> as the terminating character. It may be reading the <LF> in the buffer and overwriting your string immediatly after. Try changing your end character or checking for a null string ("").
 

Similar Topics

Hello all, thanks for reading! This is my first post so please be gentle. I have a difficult scenario that I'm struggling to make work. I have a...
Replies
6
Views
2,997
Hello, I am trying to take data from PAXI (with RS485 comms cards) and log it using a DSPSX. I have the PAXI hooked to a rotary length...
Replies
4
Views
2,963
Hi, We are trying to connect (for the 1st time) a Red Lion DSPSX to a Siemens S7. Unfortunately I do not have the S7 in front of me but I have...
Replies
0
Views
3,590
Hi folks, I got four PAXS and one PAXD connected to DSPSX via RS485. Each meter has its own number and baud rate is 9600,data bit 8, stop bit 1...
Replies
4
Views
2,122
I am having trouble using Sync Manager with a MicroLogix 1100. I am reading a 20 digit barcode and adding some more information then using the...
Replies
0
Views
2,803
Back
Top Bottom