Jump to content

ASCII Communication


Recommended Posts

In this particular case, I would be talking to a SunX sensor via RS232 using a proprietary ASCII protocol. I would need to be able to parse the incoming characters, sort out the data, and convert to numeric.

I have a working program for it on a V120, but the unit is physically too large. I may have to use a microcontroller or BASIC stamp.

It is not clear to me how I could accomplish the same thing in U90.

Link to comment
Share on other sites

  • MVP 2023

Here's a program with the SMS table configured. I don't have the hardware here right now to test it.

MB 1 triggers the send. MB 2 "should" come on when it receives the reply. You'll want the read the Help on Com Port->Jazz series to use special function 310 to get the port parameters the way you want them. You'll also want to read all the SMS Help topics. I learned many moons ago that SMS allows us to control the com port - just leave the "Use GSM Modem" unchecked.

This program automatically converts the incoming stream to a number. This may or may not work for what you're trying to do.

Good luck. Let me know if I need to bring some hardware home to bang on it some more.

Joe T.

SunXComm.U90

Link to comment
Share on other sites

Here's a program with the SMS table configured. I don't have the hardware here right now to test it.

MB 1 triggers the send. MB 2 "should" come on when it receives the reply. You'll want the read the Help on Com Port->Jazz series to use special function 310 to get the port parameters the way you want them. You'll also want to read all the SMS Help topics. I learned many moons ago that SMS allows us to control the com port - just leave the "Use GSM Modem" unchecked.

This program automatically converts the incoming stream to a number. This may or may not work for what you're trying to do.

Good luck. Let me know if I need to bring some hardware home to bang on it some more.

Joe T.

Hi Joe,

Thanks for the direction. I'll play around with it and let you know how I am making out.

Damian

Link to comment
Share on other sites

  • External Moderators

I developed an application with ASCII in Jazz following the next explanation of Help:

Communication Utilities

Use this utility to enable your controller to receive data from external devices, such as bar-code readers, via an RS232 port. Since there is no Ladder element for this function; you perform it by storing values into SIs.

Note that the communication settings stored into these SIs only take effect at power-up.

SI

Parameter

Value to Store

Notes

141

STX (Start of Text)

Select one of the 3 STX option by storing its value into SI 141:

· 0-255(ASCII)

· -1: No Start of Text (not recommended)

· -2: No Start of Text (Enables access by Unitronics PC applications)

The STX parameter indicates where the data block begins.

· -1: Note that the ASCII character '/' (backslash) cannot be used to indicate the start of the data block.

· -2: enables applications such as U90 Ladder and Remote Access to access a networked PLC. Note that these applications use the 'backslash' character ( / ) (ASCII character 47) as the Start of Text (STX) character.

142

ETX (End of Text)

Select one of the 3 ETX option by storing its value into SI 142:

· 0-255(ASCII)

· -1: ETX marked by Length

· -2: ETX marked by 'Silence'

The ETX parameter indicates where the data block ends. When the ETX is registered by the function, SB 60 turns ON.

· If you use an ASCII character (0-255), note that if this character occurs after the Length parameter defined in SI 143, SB 60 turns ON.

· Selecting -1 causes the function to use the length of a data block alone to determine its end.

· Selecting -2 causes the function to use the duration of silent time following the STX to determine the end of a data block.

143

ETX Length or Silent

· Length: up to 128

(relevant if you store -1, Length, into SI 142 to provide ETX)

· Silent: up to 24000

· This defines both the length of text, or silence, that signals the end of text.

· Note that the duration of a silent 'counter' unit is approximately 2.509 mS. The 'silent' value should be lower than the TimeOut value.

· When defined as length, SI 143 cannot exceed SI 144.

144

Maximum Length

Up to 128

· This is the maximum legal length for received text.

· When the maximum length is exceeded, the Receive Buffer is automatically cleared, and SB 60 is turned OFF, enabling new data to be received.

· This can be used to detect buffer overflow.

145

Start Address: Receive Buffer

MI Address

This MI contains the start address for the vector of registers that serves as the Receive Buffer.

60

Number of Bytes currently in Receive Buffer

Read only

SI 60 indicates how many bytes of data are currently in the Receive Buffer.

61

Number of Bytes in Receive Buffer when SB 60=1

Read only

SI 61 indicates how many bytes of data are in the Receive Buffer when SB 60 turns ON.

146

Copy Data: Format

· 0: copy each received byte

· 1: copy in groups of 4 received bytes.

· 0 causes each separate byte to be copied to a separate register including STX and ETX.

For example, if the PLC receives an STX character, 4 data bytes, and an ETX character, the data will be copied into a vector of 6 MIs: the first containing the STX, 4 MIs for the data bytes; the last MI will contain the ETX.

· 1 causes every 4 bytes to be copied to a single register, without the STX and ETX. This is used when the received data is in numeric format.

For example 12345 would be copied to 2 consecutive MIs. The first MI would contain 1234, the second would contain 5.

140

Start receiving

300

In your application, use this to call the function after you have entered all of the other parameters.

Note that when you run Test (Debug) Mode, the current value in SI 140 will not be displayed.

SB

Description

Notes

60

Data Successfully Received

Read only. Turns ON when the ETX condition is registered by the system.

61

Copy Data in Receive Buffer to MI Vector

Write only.

· Turning this SB ON causes the buffer contents to be copied to the MI vector defined in SI 145. The data will be copied according to the format defined in SI 146.

· If SI 146 is set to 0, this SB can be set at any time.

If SI 146 is set to 1, this SB can be set after SB 60 turns ON.

62

Clear Receive Buffer,

Clear SI 60,

Clear SI 61,

Reset SB 60

· This SB must be turned ON to enable a new message, or data block, to be received.

· Turn this SB ON to enable data to be received before the maximum length, defined in SI 144, is exceeded.

Note that if no data is received for a period exceeding the TimeOut, you will lose the data in the buffer.

To see how to use the Communications Utility, check the sample application Read Card - Display Number Value.U90. This may be found by accessing Sample U90 Projects from the Help menu.

This application demonstrates how to read a magnetic card number using an "IDTECH" card reader, then display that number on the PLC's screen. The card reader transmits the number in ASCII characters in this format:

< %?[CR];xxxxx?[CR] > where xxxxx is the card number.

The ASCII character used to mark the Start Of Text (STX) is < ; > (semicolon). End Of Text (ETX) is marked with the character < ? > .

Since the card number is 5 digits long, the card number is copied to 2 separate MIs. The MIs are linked to 2 variables that are shown on the PLC's screen in 2 separate Displays.

The parameters must be written into their respective operands using one scan condition. For this purpose, it is recommended to use SB 2 Power-up bit, as shown in the sample application.

  • Upvote 1
Link to comment
Share on other sites

  • MVP 2014

Also be aware that the JZ-PRG programming adaptor requires a "full" serial port on the connected device so it can scavenge power from the handshake lines. If the nature of the port on the SunX device is uncertain, have a JZ-RS4 on hand as it overcomes the limitations of the JZ-PRG, when used in RS232 mode.

Link to comment
Share on other sites

  • 5 years later...

You guys sure know these little PLCs! :)

I need some advice, and maybe a ''thumbs-up" or "thumbs-down" advice: I am working with some [very] fast-communicating sensors that use 115kb RS-232 in the following format:

<STX>[put ASCII here, in various lengths]<ETX><bcc>

where the <bcc> is the checksum as an XOR of each character prior to the <ETX> itself. The [fixed] protocol is running at 115kb, e,8,1.

I must both compose and TX such strings and read such strings from these devices, putting their fast-moving output on a screen.

I am having some difficulty in finding an HMI or maybe PLC-HMI that I can use to COMM back and forth with the sensor: I have used some of the Unitronics (U90 and [something]700 w/screen) before, but don't know if they will let me do this: can you advise?

 

Thanks, and Merry Christmas (2016).

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...