How can I create an 8-bit (byte) data structure

Hi, I’m working with Pac Control and Ignition on an automation project that requires a communication protocol to be sent to/read from a device via packets consisting of a structure of 10 elements each element consists of an 8 bit (byte).

Within the packets, I’ll need to send both binary/hex data as well as data values from 0 to 254.

At first I thought that I could use Opto’s/Pac Control’s String Tables, where the table would be declared as 0-9 giving 10 entries, of 1 Char each…making up the 8 bit byte(s) needed.

But this was quickly shot down because of the inability to store numerical data…or a 1 Char entry cannot store the digits 100.

I’ve been reading entries posted through out the User forum, but I have not ran across anything that would work in my situation. If I have missed something I apologize…

Please let me know your thoughts, and perhaps help in this matter.

PAC Control strings can hold binary data. You would use a single string of length 10 rather than a string table though. Programmatically, you would treat it like an array of bytes and refer to the byte by its index.

All of the following are equivalent to assigning the character ‘A’ to an index of a string called sPacket.

sPacket[0] = 65;
sPacket[1] = ‘A’
sPacket[2] = 0x041;

Nothing prevents you from writing any 8 bit value to a string index, so the following is valid as well:

sPacket[3] = 0;
sPacket[4] = 100;
sPacket[5] = 255;

2 Likes

Many thanks, never thought of it this way. This will solve my problem.

Spoke to soon…in building my 10 byte data packet that is in all reality declared as a string, I’ve placed needed data (both hex and number data), into the individual bytes, and tried to send the string by using the Transmit String command…but found this will not work because there are no ASCII characters in the string…therefore the Transmit String command thinks that it is an empty string, and will not send anything.

Looking now for other options…

This data needs to be sent via serial port…and yes I do open a port, and do all of the necessary checking to ensure that it is open, looks like string commands on non ASCII related information is not going to work…

Let me know if I’m wrong.

Transmit String command can send binary data. Can you post more details of what you are attempting to do?

This is an incorrect assumption as Philip also pointed out.
There is something else going on.

Just to be clear, this is PAC Control running on an EPIC?
The same EPIC is running Ignition?
You are using the EPIC serial module?

Thank you for your responses.

I’m (trying) to do machine control and have been a long time user of Ignition. Ignition runs on a separate server, and I have an Groove-Epic-PR1 PLC and I’m using the USB port with an RS-422 converter to try to communicate with the machine modules.

The machine is older and has Opto-22 Quad control modules with various brain boards. I have updated the brain boards and have all of the I/O control working with a new Ignition HMI via ModBus…I saved the more difficult for last with communication to proprietary modules that control servo valves and other machine functions.

I can send strings of ASCII data via the Transmit String command and see the machine module receive it…but eventually fault due to receiving bad data.

My data packet that I’m trying to send consists of 10 8-bit bytes, both of hex and numeric (not ASCII) data. I’ve declared a string (PBlock) with a length of 10.

The data packet that I’m trying to send follows;

// Module to initialize PowerBlock Array

Pblock[0] = 1; // Set for the address to be only one module
Pblock[0] = Pblock[0] bitor 0xC0; // Clear Fault Xmit to Host
Pblock[1] = 10; // 10 amps for current
Pblock[1] = Pblock[1] bitor 0x80; // 0 signifies Positive polarity
Pblock[2] = 100; // Volts
Pblock[3] = 20; // On Time 20 usec (Default)
Pblock[4] = 60; // Off Time 60 usec (Default)
Pblock[5] = 100; // Servo Reference
Pblock[6] = 0;
Pblock[6] = Pblock[6] bitor 0xF0; // Cap Mode SAM Set + 3.3uf Cap
Pblock[7] = 100; // Servo Gain (Default)

//Calculate Checksum for 8th element of array
Pblock[8] = 0;
Pblock[8] = XOR_Value bitxor Pblock[0];
Pblock[8] = XOR_Value bitxor Pblock[1];
Pblock[8] = XOR_Value bitxor Pblock[2];
Pblock[8] = XOR_Value bitxor Pblock[3];
Pblock[8] = XOR_Value bitxor Pblock[4];
Pblock[8] = XOR_Value bitxor Pblock[5];
Pblock[8] = XOR_Value bitxor Pblock[6];
Pblock[8] = XOR_Value bitxor Pblock[7];

// Ones Compliment for 9th element of array
Pblock[9] = bitnot Pblock[8];

As you can see I have to do some bit manipulation of the variables, the bit manipulation is to set certain (bits) required for the control…but it is still hex data.

Everything compiles, but when I run the program…Transmit String does not send anything…and within the documentation states that if the string that Transmit String is trying to send is empty, Transmit String will not send anything…

This is the actual view of the control that I’m trying to use…note that if I un comment out the last line and just send a string on “aBCDEFGH” we get Transmit String to send data…and the modules verify receipt of data…and fault

A couple of questions;

  1. I’m trying to use a 8-bit byte array or structure is there anything else other than a string that I could use in OptoScript?

  2. Next is what commands are there for sending a data packet made up of 8-bit bytes?

I really appreciate your help

Ahh, you must initialize the string to the size you need to reference the bytes by index. So init your Pblock with a string of length 10 before assigning your data to it. You can do this in the “Initial Value” box where the string is defined in PAC Control - fill the value with 10 characters of your choice. You can also assign a random string of the appropriate length in your logic before you assign your data to it too.

1 Like

Hey this worked…I just placed an initial value of 10 characters where I declared the variable (string) and everything worked…I’m now able to send both hex and numeric data.

Thank you again for your help!

1 Like