Welcome, Guest
Username: Password: Remember me

TOPIC: Arduino problem in 5.6

Arduino problem in 5.6 2 months 1 week ago #10541

  • claes
  • claes's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 2753
  • Thank you received: 371
  • Karma: 118
Hi Bill,

I think you should check the execution of the plc threads. If you look in the PlcThread objects under the PlcProcess object in the node hierarchy, you can see the actual scantime and the coverage. The coverage is in percentage and should be below 100 %. If you find any latencey or large coverage this is probably caused by delays in the Arduino communication.

/Claes
The administrator has disabled public write access.
The following user(s) said Thank You: brew

Arduino problem in 5.6 2 months 1 week ago #10543

  • brew
  • brew's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 99
  • Karma: 0
If you look in the PlcThread objects under the PlcProcess object in the node hierarchy, you can see the actual scantime and the coverage.

okay, i think this is what you want. check the screenshot below. The thing to notice is -- "LAST DELAY" updates every 1 sec or so, whenever the RX/TX lights on the arduino flash. Every light flash brings up a "LAST DELAY". So it seems that every communication with the arduino is DELAYED.
Also the internal timing of proview is still off. 40 sec ORDER DELAY is more like 3 minutes. When the arduino is plugged in.

The coverage is in percentage and should be below 100 %. If you find any latencey or large coverage this is probably caused by delays in the Arduino communication.

I did not see anything named "coverage" or any percentages. Maybe i did something wrong? Check the screenshot and tell me what i did wrong, and i will correct and send back to you.

Note: it seems the communication with the Arduino is screwy. When i use arduino 1.0.5 to load the sketches, the TX/RX lights flash every one sec.

When i use the arduino 1.8.12 to upload the sketches, the lights flash ever 3 seconds.

I have done a quick look at google, and people are saying the RXTX communicator is screwy. Not sure if that matters, but the only things that have changed are Ubuntu from 14 to 18. and proview from 5.4 to 5.6-- perhaps some kind of driver problem in ubuntu screwing up communication? Just guessing here.

Thanks for you help!
And i hope the virus is not bothering you. Everything here in the USA has ground to a halt.

drive.google.com/open?id=1y3BbAVkK6sLLQS4h-s1VYbikIReLyHDA
Last Edit: 2 months 1 week ago by brew. Reason: mistake
The administrator has disabled public write access.

Arduino problem in 5.6 2 months 1 week ago #10544

  • claes
  • claes's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 2753
  • Thank you received: 371
  • Karma: 118
The coverage is 687 % and the mean scantime is 750 ms. So you probably have a delay of about 740 ms in each transaction with the arduino. It could have something to do with the setting of the USB port.

If you can accept the slow communication with the arduino, you can create a new thread with 800 ms scantime and move the arduino IO to this thread.

/Claes
The administrator has disabled public write access.

Arduino problem in 5.6 2 months 1 week ago #10546

  • brew
  • brew's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 99
  • Karma: 0
The coverage is 687 % and the mean scantime is 750 ms. So you probably have a delay of about 740 ms in each transaction with the arduino. It could have something to do with the setting of the USB port

Thanks. Do i need to change the usb port settings?
currently i have it at 2400 baud
and i also increased the TIMEOUT to 5 from the original 1.
increasing the timeout seemed to help back when i first set this up 4 years ago.

Should i reduce the BAUD even more?

If you can accept the slow communication with the arduino,

I can accept the slow communication. It seems it has always been that slow.
I went back to the old 5.4 DEV station. and ran this same test of mean scantime. 800 for mean scantime. and 750 for coverage. It was about the same as 5.6-- {see link}
drive.google.com/open?id=1H13ekuYP8DCWGSG368MQSrGvpakeyKCk

So apparently the 5.4 version runs the same speed as the 5.6 version. There is just something in 5.6 that is messing up the timing when the arduinos are delayed, i guess.

I used arduino 1.0.5 on all the tests above.

One note. When i use arduino 1.8.12 to load the sketches, everything goes HAYWIRE. The coverage goes up to 2500, and just keeps rising the longer the program is on. {see below} Scantime is 5 SECONDS. The TX/RX lights only flash every 4 seconds, instead of every 1/2 sec.
Do you have any idea why this is happening? Why the arduino 1.8.12 is screwing up everything so royally?
I am using the same sketches, the same libraries, the same 5.6, the same program.

see link drive.google.com/open?id=1CSqakIDF2otruJOQKhGd9xTGlLl7tgkB

you can create a new thread with 800 ms scantime and move the arduino IO to this thread.


Okay, i will try that. I may be back to ask stupid questions, but that sounds like the best way to go forward.

Thanks!

bill
The administrator has disabled public write access.

Arduino problem in 5.6 2 months 1 week ago #10548

  • brew
  • brew's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 99
  • Karma: 0
UPDATE! IT WORKED!

I changed the scan rate from 0.100 to 0.800, and it became rock solid. Mean scantime of .799 and coverage of 42
This was with arduino 1.0.5
see this screenshot

drive.google.com/open?id=1uo8uGDSpYpkohjMnJK0jx2N4wNSCYe21


Note: arduino 1.8.12 is still making everything go HAWIRE
See this screenshot.
mean scantime still of 5 SECONDS
and coverage is way out of whack too.

drive.google.com/open?id=19jgT6qYUmKG_EhCy13yN_ppoKr8fOLlh

I do not know why, but anybody out there using Arduinos, Take NOTE.
I have good luck with arduino 1.0.5, and BAD luck with 1.8.12.


Thanks Claes!!!

Bill

PS
Enjoy the springtime and stay healthy!
The administrator has disabled public write access.

Arduino problem in 5.6 2 months 1 week ago #10553

  • brew
  • brew's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 99
  • Karma: 0
Hello Claes and Marc,

The timing on the DEV station was fine with 800ms.
BUT , i only had the arduinos plugged in, they wires and sensors were not hooked up.
After i changed the timing on the RTT station, which has all the 40M of wire and 23 sensors hooked up,
it seems that 800ms in proview is not slow enough.
see screenshot.

it says the scan time is 1.5 seconds
which is crazy. I have no idea why it would be going that slow.
the code on the sketch for the arduino is pretty simple.
(see below)

It should not take that long.
Did i do something wrong on the Arduino sketch?
Or is something else wrong with the settings in Proview?
Like i said, this has run just fine for 4 years.
Maybe the whole time has been with a 1.5 second scan time. i don't know. i could go back and check the 14.04 and 5.4 station if need be.

Also, i can delete code from the UNO sketch, if it is slowing the process down
The only thing i use the UNO for is reading the Temp sensors.

Any ideas??

Thanks guys!

bill

code for arduino UNO

========

Proview
// Copyright (C) 2010 SSAB Oxelosund AB.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the program, if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// Description:
// Sketch for Arduino USB board to communicate with Proview I/O
// object OtherIO:Arduino_Uno.
//

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

DeviceAddress oneThermometer = { 0x28, 0xFF, 0x21, 0x16, 0x44, 0x16, 0x03, 0x47 };
DeviceAddress twoThermometer = { 0x28, 0xFF, 0x1F, 0x18, 0x44, 0x16, 0x03, 0x74 };
DeviceAddress threeThermometer = { 0x28, 0x15, 0x0C, 0xF2, 0x05, 0x00, 0x00, 0xCC };
DeviceAddress fourThermometer = { 0x28, 0xFF, 0x6D, 0xE1, 0x43, 0x16, 0x04, 0x81 };
DeviceAddress fiveThermometer = { 0x28, 0x7B, 0x73, 0x15, 0x06, 0x00, 0x00, 0x35 };
DeviceAddress sixThermometer = { 0x28, 0x85, 0x4E, 0x28, 0x06, 0x00, 0x00, 0xE9 };
DeviceAddress sevenThermometer = { 0x28, 0x7B, 0x73, 0x15, 0x06, 0x00, 0x00, 0x11 };
DeviceAddress eightThermometer = { 0x28, 0x7B, 0x73, 0x15, 0x06, 0x00, 0x00, 0x12 };
DeviceAddress nineThermometer = { 0x28, 0xFF, 0x43, 0xF1, 0x43, 0x16, 0x03, 0x60 };
DeviceAddress tenThermometer = { 0x28, 0x68, 0x56, 0x15, 0x06, 0x00, 0x00, 0x1D };
DeviceAddress elevenThermometer = { 0x28, 0xFF, 0x37, 0xE0, 0x43, 0x16, 0x03, 0xA5 };
DeviceAddress twelveThermometer = { 0x28, 0x72, 0x12, 0x15, 0x06, 0x00, 0x00, 0x7F };
DeviceAddress thirteenThermometer = { 0x28, 0xF2, 0x73, 0x15, 0x06, 0x00, 0x00, 0x49 };
DeviceAddress fourteenThermometer = { 0x28, 0xD5, 0x80, 0x26, 0x06, 0x00, 0x00, 0x52 };
DeviceAddress fifteenThermometer = { 0x28, 0xFF, 0x77, 0xE5, 0x43, 0x16, 0x03, 0xCD };
DeviceAddress sixteenThermometer = { 0x28, 0x78, 0x6C, 0x15, 0x06, 0x00, 0x00, 0x7F };
DeviceAddress seventeenThermometer = { 0x28, 0xFF, 0x25, 0xCE, 0x43, 0x16, 0x04, 0xBC };
DeviceAddress eighteenThermometer = { 0x28, 0x6E, 0x76, 0x15, 0x06, 0x00, 0x00, 0x57 };
DeviceAddress nineteenThermometer = { 0x28, 0xBE, 0x37, 0x15, 0x06, 0x00, 0x00, 0xB7 };
DeviceAddress twentyThermometer = { 0x28, 0x69, 0x45, 0x15, 0x06, 0x00, 0x00, 0x18 };
DeviceAddress twentyoneThermometer = { 0x28, 0xE9, 0x29, 0x15, 0x06, 0x00, 0x00, 0xC2 };
DeviceAddress twentytwoThermometer = { 0x28, 0x2D, 0x3E, 0x15, 0x06, 0x00, 0x00, 0xAC };
DeviceAddress twentythreeThermometer = { 0x28, 0xED, 0x06, 0x15, 0x06, 0x00, 0x00, 0x89 };
DeviceAddress twentyfourThermometer = { 0x28, 0xFF, 0x33, 0xD1, 0x43, 0x16, 0x04, 0xFE };

byte firmware[20] = "Proview V2.0.0-1";
byte version_major = 2;
byte version_minor = 0;
byte msg = 0;
byte sts;
int val = 0;
byte amsg[50];
byte smsg[10];
byte diSize = 0;
byte doSize = 0;
byte aiSize = 0;
byte aoSize = 0;
byte diMask[10];
byte doMask[10];
byte aiMask[4];
byte aoMask[4];
int watchdogTime = 5000;
int status;
int i;
int j;
int aiList[32];
int aiCnt;
int aoList[32];
int aoCnt;
byte msgType;
byte msgId;
byte msgSize;
byte msgData[100];
byte rmsg[40];
int sizeErrorCnt = 0;
int noMessageCnt = 0;
const int delayTime = 1;
const int debug = 0;

const int MSG_TYPE_DOWRITE = 1;
const int MSG_TYPE_DIREAD = 2;
const int MSG_TYPE_AIREAD = 3;
const int MSG_TYPE_AOWRITE = 4;
const int MSG_TYPE_CONFIGURE = 5;
const int MSG_TYPE_STATUS = 6;
const int MSG_TYPE_DEBUG = 7;
const int MSG_TYPE_WRITEALL = 8;
const int MSG_TYPE_READALL = 9;
const int MSG_TYPE_CONNECTREQ = 10;
const int MSG_TYPE_CONNECTRES = 11;

const int ARD__SUCCESS = 1;
const int ARD__DICONFIG = 2;
const int ARD__DOCONFIG = 4;
const int ARD__AICONFIG = 6;
const int ARD__AOCONFIG = 8;
const int ARD__COMMERROR = 10;
const int ARD__MSGSIZE = 12;
const int ARD__NOMSG = 14;
const int ARD__CHECKSUM = 16;

void sendDebug( byte sts)
{
rmsg[0] = 4;
rmsg[1] = 0;
rmsg[2] = MSG_TYPE_DEBUG;
rmsg[3] = sts;
add_checksum( rmsg);
Serial.write( rmsg, rmsg[0]);
}

void add_checksum( byte *buf)
{
int i;
byte sum = 0;

buf[0]++;
for ( i = 0; i < buf[0] - 1; i++)
sum ^= buf;

buf[buf[0]-1] = sum;
}

int check_checksum( byte size, byte id, byte type, byte *buf)
{
int i;
byte sum = 0;

sum ^= size;
sum ^= id;
sum ^= type;
for ( i = 0; i < size - 4; i++)
sum ^= buf;

if ( buf[size-4] == sum)
return 1;
return 0;
}

//
// Reset all outputs when communication communication is down
//
void resetOutput()
{
for ( i = 0; i < doSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & doMask) != 0)
digitalWrite( i * 8 + j, LOW);
}
}
for ( i = 0; i < aoCnt; i++)
analogWrite( aoList, 0);
}

//
// Read a message from the serial port
//
int serialRead()
{
int num;
int csum;

num = Serial.available();
if ( num == 0)
return ARD__NOMSG;

msgSize = Serial.peek();
if ( num < msgSize)
return ARD__MSGSIZE;

msgSize = Serial.read();

msgId = Serial.read();
msgType = Serial.read();
msgSize -= 3;

for ( int i = 0; i < msgSize; i++)
msgData = Serial.read();

csum = check_checksum( msgSize + 3, msgId, msgType, msgData);

if ( debug) {
rmsg[0] = msgSize + 3 - 1;
rmsg[1] = msgId;
rmsg[2] = MSG_TYPE_DEBUG;
for ( int j = 0; j < msgSize-1; j++)
rmsg[j+3] = msgData[j];
add_checksum( rmsg);
Serial.write( rmsg, rmsg[0]);
}
msgSize--;

if ( !csum)
return ARD__CHECKSUM;

return ARD__SUCCESS;
}

void setup()
{
// Start serial port at the configured baud rate
Serial.begin(2400);
Serial.flush();

// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(oneThermometer, 10);
sensors.setResolution(twoThermometer, 10);
sensors.setResolution(threeThermometer, 10);
sensors.setResolution(fourThermometer, 10);
sensors.setResolution(fiveThermometer, 10);
sensors.setResolution(sixThermometer, 10);
sensors.setResolution(sevenThermometer, 10);
sensors.setResolution(eightThermometer, 10);
sensors.setResolution(nineThermometer, 10);
sensors.setResolution(tenThermometer, 10);
sensors.setResolution(elevenThermometer, 10);
sensors.setResolution(twelveThermometer, 10);
sensors.setResolution(thirteenThermometer, 10);
sensors.setResolution(fourteenThermometer, 10);
sensors.setResolution(fifteenThermometer, 10);
sensors.setResolution(sixteenThermometer, 10);
sensors.setResolution(seventeenThermometer, 10);
sensors.setResolution(eighteenThermometer, 10);
sensors.setResolution(nineteenThermometer, 10);
sensors.setResolution(twentyThermometer, 10);
sensors.setResolution(twentyoneThermometer, 10);
sensors.setResolution(twentytwoThermometer, 10);
sensors.setResolution(twentythreeThermometer, 10);
sensors.setResolution(twentyfourThermometer, 10);
}

void loop()
{

status = serialRead();
if ( status == ARD__NOMSG) {
if ( watchdogTime != 0) {
// Increment watchdog counter
noMessageCnt++;
if ( noMessageCnt * delayTime > watchdogTime)
resetOutput();
}
}
else if ( status == ARD__MSGSIZE) {
sizeErrorCnt++;
if ( sizeErrorCnt > 50) {
Serial.flush();
sizeErrorCnt = 0;
}
}
else if ( (status & 1) != 0) {
// A message is received
sizeErrorCnt = 0;
noMessageCnt = 0;

if ( msgType == MSG_TYPE_DOWRITE) {
// Write digital outputs

if ( msgSize == doSize) {
for ( i = 0; i < doSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & doMask) != 0) {
if ( ((1 << j) & msgData) != 0)
digitalWrite( i * 8 + j, HIGH);
else
digitalWrite( i * 8 + j, LOW);
}
}
}
sts = ARD__SUCCESS;
}
else {
sts = ARD__COMMERROR;
}
}
else if ( msgType == MSG_TYPE_AOWRITE) {
// Write analog outputs

if ( msgSize == aoCnt) {
for ( i = 0; i < aoCnt; i++)
analogWrite( aoList, msgData);

sts = ARD__SUCCESS;
}
else {
sts = ARD__COMMERROR;
}
}
else if ( msgType == MSG_TYPE_WRITEALL) {
// Write digital outputs

if ( msgSize == doSize + aoCnt) {
for ( i = 0; i < doSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & doMask) != 0) {
if ( ((1 << j) & msgData) != 0)
digitalWrite( i * 8 + j, HIGH);
else
digitalWrite( i * 8 + j, LOW);
}
}
}

for ( i = 0; i < aoCnt; i++)
analogWrite( aoList, msgData[doSize + i]);

sts = ARD__SUCCESS;
}
else {
sts = ARD__COMMERROR;
}
}
else if ( msgType == MSG_TYPE_DIREAD) {
// Read Digital inputs
smsg[0] = diSize + 3;
smsg[1] = msgId;
smsg[2] = MSG_TYPE_DIREAD;
for ( i = 0; i < diSize; i++) {
smsg = 0;
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & diMask) != 0) {
val = digitalRead( i * 8 + j);
if ( val == HIGH)
smsg |= 1 << j;
}
}
}
add_checksum( smsg);
Serial.write( smsg, smsg[0]);
}
else if ( msgType == MSG_TYPE_AIREAD) {
// Read analog inputs
amsg[0] = aiCnt * 2 + 3;
amsg[1] = msgId;
amsg[2] = MSG_TYPE_AIREAD;
sensors.requestTemperatures(); // Send the command to get temperatures
for ( i = 0; i < aiCnt; i++) {
switch ( i) {
case 0:
val = sensors.getTempC(oneThermometer) * 10; // Temperature values instead of aiRead()
break;
case 1:
val = sensors.getTempC(twoThermometer) * 10; // Temperature values instead of aiRead()
break;
case 2:
val = sensors.getTempC(threeThermometer) * 10; // Temperature values instead of aiRead()
break;
case 3:
val = sensors.getTempC(fourThermometer) * 10; // Temperature values instead of aiRead()
break;
case 4:
val = sensors.getTempC(fiveThermometer) * 10; // Temperature values instead of aiRead()
break;
case 5:
val = sensors.getTempC(sixThermometer) * 10; // Temperature values instead of aiRead()
break;
case 6:
val = sensors.getTempC(sevenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 7:
val = sensors.getTempC(eightThermometer) * 10; // Temperature values instead of aiRead()
break;
case 8:
val = sensors.getTempC(nineThermometer) * 10; // Temperature values instead of aiRead()
break;
case 9:
val = sensors.getTempC(tenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 10:
val = sensors.getTempC(elevenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 11:
val = sensors.getTempC(twelveThermometer) * 10; // Temperature values instead of aiRead()
break;
case 12:
val = sensors.getTempC(thirteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 13:
val = sensors.getTempC(fourteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 14:
val = sensors.getTempC(fifteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 15:
val = sensors.getTempC(sixteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 16:
val = sensors.getTempC(seventeenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 17:
val = sensors.getTempC(eighteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 18:
val = sensors.getTempC(nineteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 19:
val = sensors.getTempC(twentyThermometer) * 10; // Temperature values instead of aiRead()
break;
case 20:
val = sensors.getTempC(twentyoneThermometer) * 10; // Temperature values instead of aiRead()
break;
case 21:
val = sensors.getTempC(twentytwoThermometer) * 10; // Temperature values instead of aiRead()
break;
case 22:
val = sensors.getTempC(twentythreeThermometer) * 10; // Temperature values instead of aiRead()
break;
case 23:
val = sensors.getTempC(twentyfourThermometer) * 10; // Temperature values instead of aiRead()
break;
default:
val = 0;
}
amsg[i*2 + 3] = val >> 8;
amsg[i*2 + 1 + 3] = val & 0xFF;
}
add_checksum( amsg);
Serial.write( amsg, amsg[0]);
}
else if ( msgType == MSG_TYPE_READALL) {
// Read Digital inputs
amsg[0] = diSize + aiCnt * 2 + 3;
amsg[1] = msgId;
amsg[2] = MSG_TYPE_READALL;
for ( i = 0; i < diSize; i++) {
amsg = 0;
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & diMask) != 0) {
val = digitalRead( i * 8 + j);
if ( val == HIGH)
amsg |= 1 << j;
}
}
}

sensors.requestTemperatures(); // Send the command to get temperatures
for ( i = 0; i < aiCnt; i++) {
switch ( i) {
case 0:
val = sensors.getTempC(oneThermometer) * 10; // Temperature values instead of aiRead()
break;
case 1:
val = sensors.getTempC(twoThermometer) * 10; // Temperature values instead of aiRead()
break;
case 2:
val = sensors.getTempC(threeThermometer) * 10; // Temperature values instead of aiRead()
break;
case 3:
val = sensors.getTempC(fourThermometer) * 10; // Temperature values instead of aiRead()
break;
case 4:
val = sensors.getTempC(fiveThermometer) * 10; // Temperature values instead of aiRead()
break;
case 5:
val = sensors.getTempC(sixThermometer) * 10; // Temperature values instead of aiRead()
break;
case 6:
val = sensors.getTempC(sevenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 7:
val = sensors.getTempC(eightThermometer) * 10; // Temperature values instead of aiRead()
break;
case 8:
val = sensors.getTempC(nineThermometer) * 10; // Temperature values instead of aiRead()
break;
case 9:
val = sensors.getTempC(tenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 10:
val = sensors.getTempC(elevenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 11:
val = sensors.getTempC(twelveThermometer) * 10; // Temperature values instead of aiRead()
break;
case 12:
val = sensors.getTempC(thirteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 13:
val = sensors.getTempC(fourteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 14:
val = sensors.getTempC(fifteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 15:
val = sensors.getTempC(sixteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 16:
val = sensors.getTempC(seventeenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 17:
val = sensors.getTempC(eighteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 18:
val = sensors.getTempC(nineteenThermometer) * 10; // Temperature values instead of aiRead()
break;
case 19:
val = sensors.getTempC(twentyThermometer) * 10; // Temperature values instead of aiRead()
break;
case 20:
val = sensors.getTempC(twentyoneThermometer) * 10; // Temperature values instead of aiRead()
break;
case 21:
val = sensors.getTempC(twentytwoThermometer) * 10; // Temperature values instead of aiRead()
break;
case 22:
val = sensors.getTempC(twentythreeThermometer) * 10; // Temperature values instead of aiRead()
break;
case 23:
val = sensors.getTempC(twentyfourThermometer) * 10; // Temperature values instead of aiRead()
break;
default:
val = 0;
}
amsg[diSize + i*2 + 3] = val >> 8;
amsg[diSize + i*2 + 1 + 3] = val & 0xFF;
}
add_checksum( amsg);
Serial.write( amsg, amsg[0]);
}
else if ( msgType == MSG_TYPE_CONFIGURE) {
// Configure message
int offs = 0;
sts = ARD__SUCCESS;

if ( debug) {
smsg[0] = msgSize + 3;
smsg[1] = msgId;
smsg[2] = MSG_TYPE_DEBUG;
for ( int j = 0; j < msgSize; j++)
smsg[j+3] = msgData[j];
add_checksum( smsg);
Serial.write( smsg, smsg[0]);
}

watchdogTime = msgData[offs++] * 100;

diSize = msgData[offs++];
if ( diSize > 10) {
diSize = 10;
sts = ARD__DICONFIG;
}
if ( sts & 1 != 0) {
for ( i = 0; i < diSize; i++)
diMask = msgData[offs++];
}

if ( sts & 1 != 0) {
doSize = msgData[offs++];
if ( doSize > 10) {
doSize = 10;
sts = ARD__DOCONFIG;
}
}
if ( sts & 1 != 0) {
for ( i = 0; i < doSize; i++)
doMask = msgData[offs++];
}

if ( sts & 1 != 0) {
aiSize = msgData[offs++];
if ( aiSize > 4) {
aiSize = 4;
sts = ARD__AICONFIG;
}
}

if ( sts & 1 != 0) {
for ( i = 0; i < aiSize; i++)
aiMask = msgData[offs++];
}

if ( sts & 1 != 0) {
aoSize = msgData[offs++];
if ( aoSize > 4) {
aoSize = 4;
sts = ARD__AOCONFIG;
}
}

if ( sts & 1 != 0) {
for ( i = 0; i < aoSize; i++)
aoMask = msgData[offs++];
}

if ( sts & 1 != 0) {
// Set Di pinmode
for ( i = 0; i < diSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & diMask) != 0)
pinMode( i * 8 + j, INPUT);
}
}

// Set Do pinmode
for ( i = 0; i < doSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & doMask) != 0)
pinMode( i * 8 + j, OUTPUT);
}
}

// Create list of configured Ai
aiCnt = 0;
for ( i = 0; i < aiSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & aiMask) != 0) {
aiList[aiCnt] = i * 8 + j;
aiCnt++;
}
}
}

// Create list of configured Ao
aoCnt = 0;
for ( i = 0; i < aoSize; i++) {
for ( j = 0; j < 8; j++) {
if ( ((1 << j) & aoMask) != 0) {
aoList[aoCnt] = i * 8 + j;
aoCnt++;
}
}
}
}

// Send configuration status
smsg[0] = 4;
smsg[1] = msgId;
smsg[2] = MSG_TYPE_STATUS;
smsg[3] = sts;
add_checksum( smsg);
Serial.write(smsg, smsg[0]);

}
else if ( msgType == MSG_TYPE_CONNECTREQ) {
// Connect reqeust
amsg[0] = 23 + 3;
amsg[1] = msgId;
amsg[2] = MSG_TYPE_CONNECTRES;
amsg[3] = ARD__SUCCESS;
amsg[4] = version_major;
amsg[5] = version_minor;
for ( i = 0; i < 20; i++)
amsg[i+6] = firmware;
add_checksum( amsg);
Serial.write( amsg, amsg[0]);
}
}
else {
// Return error status
smsg[0] = 4;
smsg[1] = msgId;
smsg[2] = MSG_TYPE_STATUS;
smsg[3] = status;
add_checksum( smsg);
Serial.write(smsg, smsg[0]);

}

delay(delayTime);
}
Attachments:
The administrator has disabled public write access.
Time to create page: 2.320 seconds