6 uarts on 2xEsp32

pluciorx
Posts: 1
Joined: Mon Dec 09, 2019 8:33 pm

6 uarts on 2xEsp32

Postby pluciorx » Tue Dec 10, 2019 6:54 am

Hi
I have been fighting with this issue for about a month,
I have 4 external Rs232 connected devices connected to 2x ESP32

ESP's are interconnected between them using Serial2 (UART2) first esp acts as master and have an lcd and a keyboard when a code is entered, this code is then forwarded to slave and indicates readiness for receiving data,
Each ESP makes a GET request to a server once data is received on rs232,
the problem is that it works at completely random,when each rs port is tested separately i can get all the readings done.

When all ports receive data at the same time (rs devices are sending data virtually at the same moment) very often data is lost most often slave uart 1 ( serial1 ) does not get any data in the buffer (completely deaf)


each string starts with a digit number and ends with "\n\r"

Is there any obvious mistakes in the codes below?


Master code:

Code: Select all

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>


HTTPClient http;
const byte n_rows = 4;
const byte n_cols = 4;
char keys[n_rows][n_cols] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[n_rows] = { 13, 12, 14, 27 }; //connect to the row pinouts of the keypad
byte colPins[n_cols] = { 26, 25, 33 }; //connect to the column pinouts of the keypad

Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, n_rows, n_cols);
#define LCD_COLS 21

LiquidCrystal_I2C lcd(0x27, LCD_COLS, 4); // set the LCD address to 0x3F for a 16 chars and 2 line display

uint32_t stateTime = 0;
#define LED_BUILD_IN 2

const unsigned int COM_BAUD = 9600;
//Iputs
const unsigned int MAX_INPUT = 256;

//GFX
const char EMPTY_LINE[LCD_COLS] = { "                    " };
const char UNKNOWN_STATE_LINE[LCD_COLS] = { "BLAD: RESTART " };
const char WIFI_CONNECTING_LINE[LCD_COLS] = { "LACZE Z WIFI.." };
const char ENTER_CODE_LINE[LCD_COLS] = { "WPISZ TestId:       " };
const char UPLOADING_STR[LCD_COLS] = { "WYSYLAM DANE..    " };
const char UPLOADING_OK_STR[LCD_COLS] = { "DANE ZAPISANE...  " };
const char UPLOADING_FAIL_STR[LCD_COLS] = { "SERWER KAPUT !! " };
const char INCOMPLETE_DATA_STR[LCD_COLS] = { "NIEPELNE DANE:    " };
const char CLEAR_BUFF[LCD_COLS] = { "CZYSZCZENIE BUFFOR" };
const char CANCEL_CONFIRM_LINE[LCD_COLS] = { "*-CZYSC   #-OK " };
const char CANCEL_LINE[LCD_COLS] = { "*-USUN           " };
const char WAITING_FOR_DATA[LCD_COLS] = { "CZEKAM NA DANE... " };

//Wifi


const char* ssid = "www.dotiart.com_2";
const char* password = "xxxxx";



String LFDNR, PRG, FD, FZ, AD, AZ, BZ, MZ, GWGU, GWGO, GWFU, GWFO, ERGPA, ERGTXT, ERGPA2, PrgName, MessDru, VOL, Ergml1, Ergml2, COM;

char  _enteredCode[9] = { "........" };
int key_counter = 0;

char input_line1[MAX_INPUT];


enum E_STATE {
	READ_KB,
	SERIAL_READING,
	SERIAL0,
	SERIAL1,
	SERIAL2,
	CLR_BUFF,
	INCOMPLETE_DATA,
	REMOTE_SENDING,
	SENDING_OK,
	SENDING_FAIL,
};

E_STATE _state;



void setup() {

	pinMode(LED_BUILD_IN, OUTPUT);
	digitalWrite(LED_BUILD_IN, LOW);

	//lcd
	delay(100);
	lcd.init();
	lcd.begin(20, 4);
	lcd.clear();
	lcd.backlight();
	lcd.setCursor(0, 1);

	//wifi:
	WiFi.begin(ssid, password);
	while (WiFi.status() != WL_CONNECTED) {

		DrawWIFIConnectingScreen();
		delay(500);
	}
	delay(3000); // lets wait for slave to start

	Serial.begin(COM_BAUD, SERIAL_8N1, 23, 1);

	Serial1.begin(COM_BAUD, SERIAL_8N1, 18, 19);

	Serial2.begin(115200, SERIAL_8N1); //interconnect after we are connected to wifi

	delay(100);

	_state = READ_KB;
	delay(3000);
	SendCmdToSlave("i");

	DrawEnterKeyScreen();

}


void process_data(String data, int serialNum)
{
	FillVariables(data, serialNum);

	DrawUploadingScreen();
	if (WiFi.status() == WL_CONNECTED)
	{
		
		uploadData("http://xxxx:5000/Api/record");
	}
	else
	{
		WiFi.reconnect();
		int rtryCntr = 0;
		while (WiFi.status() != WL_CONNECTED && rtryCntr < 5) {
			rtryCntr++;
			DrawWIFIConnectingScreen();
			delay(500);
		}

		uploadData("http://xxxx:5000/Api/record");
	}

}

void uploadData(String baseUrl)
{
	String url = baseUrl
		+ "?LFDNR=" + LFDNR
		+ "&PRG=" + PRG
		+ "&FD=" + FD
		+ "&FZ=" + FZ
		+ "&AD=" + AD
		+ "&AZ=" + AZ
		+ "&BZ=" + BZ
		+ "&MZ=" + MZ
		+ "&GWGU=" + GWGU
		+ "&GWGO=" + GWGO
		+ "&GWFU=" + GWFU
		+ "&GWFO=" + GWFO
		+ "&ERGPA=" + ERGPA
		+ "&ERGTXT=" + ERGTXT
		+ "&ERGPA2=" + ERGPA2
		+ "&PrgName=" + PrgName
		+ "&MessDru=" + MessDru
		+ "&VOL=" + VOL
		+ "&Ergml1=" + Ergml1
		+ "&Ergml2=" + Ergml2
		+ "&CODE=" + _enteredCode
		+ "&SRC=COM" + COM;

	Serial.println(url);
	http.begin(url);

	int httpCode = http.GET();

	if (httpCode > 0) { //Check the returning code


	}
	else {
		if (httpCode == HTTPC_ERROR_CONNECTION_REFUSED)
		{


		}
	}
	http.end();
}

void FillVariables(String data, int serialNum)
{

	int spcIndex = data.indexOf(" ");

	LFDNR = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	PRG = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	FD = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	FZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	AD = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	AZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	BZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	MZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWGU = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWGO = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWFU = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWFO = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	ERGPA = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = 6; //fixed width
	ERGTXT = data.substring(0, spcIndex);
	ERGTXT.trim();
	ERGTXT.replace(" ", "%20");

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	ERGPA2 = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	if (spcIndex < 8)spcIndex = 8;
	PrgName = data.substring(0, spcIndex);
	PrgName.trim();
	PrgName.replace(" ", "%20");

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	MessDru = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	VOL = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	Ergml1 = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	Ergml2 = data.substring(0, spcIndex);

	COM = String(serialNum);
}

void processCom(const char inByte, int serialNum)
{
	static unsigned int input_pos = 0;

	switch (inByte)
	{

	case '\n':   // end of text
	{
		input_line1[input_pos] = 0;  // terminating null byte
		input_pos = 0;
		String tempStr = input_line1;
		tempStr.trim();
		Serial.print("Reveived string on com:");
		Serial.println(serialNum);
		if (tempStr.length() > 110)
		{
			process_data(tempStr, serialNum);
		}

		if (serialNum == 1)
		{
			Serial.end();
			delay(100);
			Serial.begin(COM_BAUD, SERIAL_8N1, 23, 1);
			delay(100);
		}
		else
		{

			Serial1.end();
			delay(100);
			Serial1.begin(COM_BAUD, SERIAL_8N1, 18, 19);
			delay(100);
		}

	}
	break;
	case '\r':   // discard carriage return - t should never get here
		break;

	default: {
		// keep adding if not full ... allow for terminating null byte
		if (input_pos == 0 && !isDigit(inByte)) break;
		if (input_pos < (MAX_INPUT - 1))
			input_line1[input_pos++] = inByte;
	}break;

	}  // end of switch
}


bool SendCmdToSlave(String cmd)
{
	Serial2.println(cmd);
}

void SetStateFromRemote()
{
	if (Serial2.available() > 0)
	{
		char chr = Serial2.read();
		switch (chr)
		{
		case 's': {
			_state = REMOTE_SENDING;
		}break;
		case 'o': {
			_state = SENDING_OK;
		}break;
		case 'f': {
			_state = SENDING_FAIL;
		}break;
		case 'r': {
			_state = SERIAL_READING;
		}break;
		default:
		{

		}break;
		}
		Serial2.flush();
	}
}

void loop() {
	delay(5);
	SetStateFromRemote();

	switch (_state)
	{
	case READ_KB: {
		delay(20);
		char key = myKeypad.getKey();
		if (key != NULL) {
			if (key == '#' && key_counter == 8)
			{
				key_counter = 0;
				_state = CLR_BUFF;

				DrawClearBuffer();
				//send code and read instruction to slave
				SendCmdToSlave("r" + String(_enteredCode));
				break;
			}

			if (key == '*')
			{
				memset(_enteredCode, 0, sizeof(_enteredCode));
				key_counter = 0;
				lcd.setCursor(0, 1);
				lcd.print(EMPTY_LINE);
				DrawEnterKeyScreen();
				_state = READ_KB;
				SendCmdToSlave("i");
				break;
			}
			if (key_counter == 8)
			{
				break;
			}

			_enteredCode[key_counter] = key;
			key_counter++;
		}

		lcd.setCursor(0, 1);
		lcd.print('[');
		lcd.print(_enteredCode);
		lcd.print(']');

	}break;

	case SERIAL_READING: {

		digitalWrite(LED_BUILD_IN, HIGH);

		DrawWaitForSerialScreen();
		char key = myKeypad.getKey();
		if (key != NULL) {
			if (key == '*')
			{
				DrawEnterKeyScreen();
				_state = READ_KB;
				SendCmdToSlave("i");
				break;
			}
		}

		_state = SERIAL0;


	}break;
	case SERIAL0: {

		while (Serial.available() > 0)
		{
			char chr = Serial.read();
			processCom(chr, 1);

		}
		_state = SERIAL1;
	}break;
	case SERIAL1: {

		while (Serial1.available())
		{
			char chr = Serial1.read();
			processCom(chr, 2);
		}

		_state = SERIAL_READING;
	}break;

	case CLR_BUFF: {
		Serial.flush();
		Serial1.flush();

		_state = SERIAL_READING;
	}break;
	case INCOMPLETE_DATA: {

		DrawIncompleteString();
		delay(500);
		_state = SERIAL_READING;
	}break;
	case REMOTE_SENDING: {

		DrawUploadingScreen();
		delay(500);

		_state = SERIAL_READING;

	}break;
	case SENDING_OK: {

		DrawUploadingOKScreen();
		delay(500);

		_state = SERIAL_READING;

	}break;
	case SENDING_FAIL: {

		DrawUploadingFailScreen();
		delay(1500);

		_state = SERIAL_READING;

	}break;
	default:
	{
		DrawUnknownStateScreen();
	}break;

	}
}

void DrawUnknownStateScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 1);
	lcd.print(UNKNOWN_STATE_LINE);

	lcd.setCursor(0, 2);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawWIFIConnectingScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 1);
	lcd.print(WIFI_CONNECTING_LINE);


	lcd.setCursor(0, 2);
	lcd.print(ssid);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawUploadingScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(UPLOADING_STR);
	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawUploadingOKScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(UPLOADING_OK_STR);
	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawUploadingFailScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(UPLOADING_FAIL_STR);
	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawIncompleteString()
{
	lcd.setCursor(0, 0);
	lcd.print(INCOMPLETE_DATA_STR);
	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawClearBuffer()
{
	lcd.setCursor(0, 0);
	lcd.print(CLEAR_BUFF);
	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 3);
	lcd.print(EMPTY_LINE);
}
void DrawEnterKeyScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(ENTER_CODE_LINE);

	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print("IP:");
	lcd.print(WiFi.localIP());
	lcd.setCursor(0, 3);
	lcd.print(CANCEL_CONFIRM_LINE);
}
void DrawWaitForSerialScreen()
{
	lcd.setCursor(0, 0);
	lcd.print(WAITING_FOR_DATA);

	lcd.setCursor(0, 1);
	lcd.print(EMPTY_LINE);
	lcd.setCursor(0, 2);
	lcd.print("TestID:     ");
	lcd.print(_enteredCode);
	lcd.setCursor(0, 3);
	lcd.print(CANCEL_LINE);
}
Slave code :

Code: Select all

//Iputs
#include <SoftwareSerial.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;

const unsigned int MAX_INPUT = 256;

char buff_com_slave[MAX_INPUT];

const unsigned int COM_BAUD = 9600;
char  _enteredCode[9] = { "........" };

const char* ssid = "www.dotiart.com_2";
const char* password = "";

String LFDNR, PRG, FD, FZ, AD, AZ, BZ, MZ, GWGU, GWGO, GWFU, GWFO, ERGPA, ERGTXT, ERGPA2, PrgName, MessDru, VOL, Ergml1, Ergml2, COM;

char input_line1[MAX_INPUT];


#define LED_BUILD_IN 2

enum E_STATE {
	IDLE,
	SERIAL_READING,
	SERIAL0,
	SERIAL1
};



E_STATE _state = IDLE;

void readMasterState(const char inByte)
{
	static unsigned int input_pos = 0;

	switch (inByte)
	{

	case '\n':   // end of text
	{
		buff_com_slave[input_pos] = 0;  // terminating null byte
		input_pos = 0;
		String tempStr = buff_com_slave;
		tempStr.trim();
		Serial.println(tempStr);
		SetStateFromRemote(tempStr);

	}
	break;
	case '\r':   // discard carriage return - t should never get here
		break;

	default: {
		// keep adding if not full ... allow for terminating null byte
		if (input_pos < (MAX_INPUT - 1))
			buff_com_slave[input_pos++] = inByte;
	}break;

	}  // end of switch
}

bool SendCmdToMaster(String cmd)
{
	Serial2.println(cmd);
	Serial2.flush();
}
// the setup function runs once when you press reset or power the board
void setup() {

	pinMode(LED_BUILD_IN, OUTPUT);

	//wifi:
	WiFi.begin(ssid, password);
	while (WiFi.status() != WL_CONNECTED) {

		delay(500);
	}
	delay(500);
	digitalWrite(LED_BUILD_IN, HIGH);
	delay(250);
	digitalWrite(LED_BUILD_IN, LOW);


	Serial.begin(COM_BAUD, SERIAL_8N1);
	Serial1.begin(COM_BAUD, SERIAL_8N1, 18, 19);
	Serial2.begin(115200, SERIAL_8N1); //interconnect	

	Serial1.setRxBufferSize(128);
	Serial.setRxBufferSize(128);

	_state = IDLE;

	Serial.println("Slave OK");
}


void loop() {
	delay(5);
	//check if there was any state change on master
	while (Serial2.available())
	{
		char chr2 = Serial2.read();
		readMasterState(chr2);

	}

	switch (_state)
	{
	case IDLE: {

		digitalWrite(LED_BUILD_IN, LOW);

	}break;

	case SERIAL_READING: {

		digitalWrite(LED_BUILD_IN, HIGH);

		_state = SERIAL0;
	}break;
	case SERIAL0: {

		while (Serial.available())
		{
			char chr3 = Serial.read();
			processCom(chr3, 3);
		}
		_state = SERIAL1;
	}break;
	case SERIAL1: {
		while (Serial1.available())
		{
			char chr4 = Serial1.read();
			processCom(chr4, 4);
		}
		_state = SERIAL0;
	}break;
	}

}

void SetStateFromRemote(String cmd)
{
	if (cmd == "i") {
		_state = IDLE;
		Serial.println(" IDLE command:");
	}
	if (cmd.startsWith("r")) {
		Serial.println(" ReadSerial command:");
		cmd.substring(1).toCharArray(_enteredCode, sizeof(_enteredCode));
		Serial.println(_enteredCode);
		_state = SERIAL_READING;
	}
}


void processCom(const char inByte, int serialNum)
{
	static unsigned int input_pos = 0;

	switch (inByte)
	{

	case '\n':   // end of text
	{
		input_line1[input_pos] = 0;  // terminating null byte
		input_pos = 0;
		String tempStr = input_line1;
		tempStr.trim();

		Serial.print("Reveived string on com:");
		Serial.println(serialNum);

		if (tempStr.length() > 110)
		{
			process_data(tempStr, serialNum);
		}

		if (serialNum == 3)
		{
			Serial.end();
			delay(100);
			Serial1.begin(COM_BAUD, SERIAL_8N1);
			delay(100);
		}
		if (serialNum == 4)
		{

			Serial1.end();
			delay(100);
			Serial1.begin(COM_BAUD, SERIAL_8N1, 18, 19);
			delay(100);
		}

	}
	break;
	case '\r':   // discard carriage return - t should never get here
		break;

	default: {
		// keep adding if not full ... allow for terminating null byte
		if (input_pos == 0 && !isDigit(inByte)) break;
		if (input_pos < (MAX_INPUT - 1))
			input_line1[input_pos++] = inByte;
	}break;

	}  // end of switch
}

void process_data(String data, int serialNum)
{
	FillVariables(data, serialNum);
	SendCmdToMaster("s");
	if (WiFi.status() == WL_CONNECTED)
	{
		
		uploadData("http://xxxxx:5000/Api/record");
	}
	else
	{
		WiFi.reconnect();
		int rtryCnt = 0;
		while (WiFi.status() != WL_CONNECTED && rtryCnt < 5) {
			rtryCnt++;
			delay(500);
		}

		uploadData("http://xxxxx:5000/Api/record");

	}
}

void uploadData(String baseUrl)
{

	String url = baseUrl
		+ "?LFDNR=" + LFDNR
		+ "&PRG=" + PRG
		+ "&FD=" + FD
		+ "&FZ=" + FZ
		+ "&AD=" + AD
		+ "&AZ=" + AZ
		+ "&BZ=" + BZ
		+ "&MZ=" + MZ
		+ "&GWGU=" + GWGU
		+ "&GWGO=" + GWGO
		+ "&GWFU=" + GWFU
		+ "&GWFO=" + GWFO
		+ "&ERGPA=" + ERGPA
		+ "&ERGTXT=" + ERGTXT
		+ "&ERGPA2=" + ERGPA2
		+ "&PrgName=" + PrgName
		+ "&MessDru=" + MessDru
		+ "&VOL=" + VOL
		+ "&Ergml1=" + Ergml1
		+ "&Ergml2=" + Ergml2
		+ "&CODE=" + _enteredCode
		+ "&SRC=COM" + COM;

	http.begin(url);
	Serial.println(url);

	int httpCode = http.GET();

	if (httpCode > 0) { //Check the returning code

	}
	else {

		if (httpCode == HTTPC_ERROR_CONNECTION_REFUSED)
		{


		}
	}
	http.end();

}

void FillVariables(String data, int serialNum)
{

	int spcIndex = data.indexOf(" ");

	LFDNR = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	PRG = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	FD = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	FZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	AD = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	AZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	BZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	MZ = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWGU = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWGO = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWFU = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	GWFO = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	ERGPA = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = 6; //fixed width
	ERGTXT = data.substring(0, spcIndex);
	ERGTXT.trim();
	ERGTXT.replace(" ", "%20");

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	ERGPA2 = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	if (spcIndex < 8)spcIndex = 8;
	PrgName = data.substring(0, spcIndex);
	PrgName.trim();
	PrgName.replace(" ", "%20");

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	MessDru = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	VOL = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	Ergml1 = data.substring(0, spcIndex);

	data = data.substring(spcIndex, data.length());
	data.trim();
	spcIndex = data.indexOf(" ");
	Ergml2 = data.substring(0, spcIndex);

	COM = String(serialNum);
}

Who is online

Users browsing this forum: No registered users and 72 guests