Rockwell Automation 5370 Color CVIM Communications Manual User Manual
Page 132

Chapter 5
Using the RS–232 Ports
5–64
/* Print options menu on the screen */
do {
printf (”\n\nOperations: \n\n”);
printf (”0. Echo ’HELLO’\n”);
printf (”1. Trigger Tool Set\n”);
printf (”2. Read Discrete Results\n”);
printf (”3. Read Results Block 1\n”);
printf (”4. Read configuration\n”);
printf (”5. Write configuration\n”);
printf (”\nEnter operation number (0–5) or –1 to quit: ”);
scanf(”%d”, &op_num ); /* Convert user string input to a number
*/
replen = err = 0; /* Initialize control variables */
switch (op_num) /* Determine what user selected */
{
case 0: /* echo hello */
{
err = send_message (portnum,”\001\000\001HELLO”,8);
if (!err)
err = get_message(portnum,reply,&replen);
if (replen && !err)
{
printf (”Response: ”);
for (x=0; x<replen; x++)
printf (”%c ”,reply[x]);
printf (”\n”);
}
} break;
case 1: /* trigger tool set */
{
err = send_message (portnum,”\011”,1); /* no reply */
} break;
case 2: /* read discrete results */
{
err = send_message (portnum,”\007\000\001\000”,4);
if (!err)
err = get_message(portnum,reply,&replen);
if (replen && !err)
{
printf (”Response: ”);
for (x=0; x<replen; x++)
printf (”%02X ”,reply[x]);
printf (”\n”);
}
} break;