Circular Buffer Reader, I'm stuck - c

I am trying to implement a circular buffer, I'm writing to it just fine, all the received data is there, but something about my function to read from it doesn't work. No data gets saved into MtoHSdata.
The data I'm trying to read has a Start (>) and End (<) symbol, and is supposed to be sent via USART1.
Read data function:
void MtoHS(struct remoteM *Buff)
{
BYTE k = 0;
static BYTE st = 1;
switch (st)
{
case 1:
{
if ((*Buff).wr != (*Buff).re)
{
(*Buff).re = ((*Buff).re + 1) % (*Buff).max;
if ((*Buff).Buffer[(*Buff).re] == '>') // > == Start Symbol
{
k = 0;
MtoHSdata[k] = (*Buff).Buffer[(*Buff).re];
}
else if ((*Buff).Buffer[(*Buff).re] == '<') // < == End Symbol
{
MtoHSdata[k] = (*Buff).Buffer[(*Buff).re];
st = 5;
}
else
{
MtoHSdata[k] = (*Buff).Buffer[(*Buff).re]; // Data
k++;
}
}
}
break;
/* When End Symbol was read, send data to M */
case 5:
{
BYTE i = 0;
while (MtoHSdata[i] != '<')
{
USART_SendData(USART1, MtoHSdata[i]);
i++;
}
}
break;
default:
{
st = 1;
}
}
return;
}
Write data function (interrupt):
void USART1_IRQHandler(void)
{
if (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)
{
uint16_t byteM = 0;
USART_GetITStatus(USART1, USART_IT_ORE);
byteM = USART_ReceiveData(USART1);
pRXD5->Buffer[pRXD5->wr] = byteM;
pRXD5->wr = (pRXD5->wr + 1) % pRXD5->max;
}
return;
}
I'm calling MtoHS function with the parameter 'pRXD5'.
Could anyone please tell me what I'm doing wrong?

Related

Is there any possible way to loop strcmp function in c language?

I'm a freshman in university and currently learning the C language. Last night I've just found really big problem with my code but there's nothing I could fix with my terrible skills... can you help me to solve this?
(condition)
you are trying to login with id / pw and only have 3 chances.
there are 5 id's and pw's on each.
if id does not exist, print id does not exist.
if id exists but pw does not match, print pw does not match.
if id and pw match, print login successful and exit program.
is there any way to loop the strcmp functions which marked?
Here's code below.
#include <stdio.h>
#include <string.h>
int main(void) {
char id0[] = "user1";
char id1[] = "user2";
char id2[] = "user3";
char id3[] = "user4";
char id4[] = "user5";
char pw0[] = "pass1";
char pw1[] = "pass2";
char pw2[] = "pass3";
char pw3[] = "pass4";
char pw4[] = "pass5";
char idsol[100] = { 0 };
char pwsol[100] = { 0 };
int idmat = 1;
int pwmat = 1;
int logstack = 0;
for (int i = 0; i <= 2;) {
logstack = i;
rewind(stdin);
printf("ID: ");
scanf_s("%s", idsol, sizeof(idsol));
printf("PW: ");
scanf_s("%s", pwsol, sizeof(pwsol));
if (strcmp(idsol, id0) == 0) { //i want to make these 5 blocks in one command.
idmat = 0;
if (strcmp(pwsol, pw0) == 0) {
pwmat = 0;
}
}
if (strcmp(idsol, id1) == 0) {
idmat = 0;
if (strcmp(pwsol, pw1) == 0) {
pwmat = 0;
}
}
if (strcmp(idsol, id2) == 0) {
idmat = 0;
if (strcmp(pwsol, pw2) == 0) {
pwmat = 0;
}
}
if (strcmp(idsol, id3) == 0) {
idmat = 0;
if (strcmp(pwsol, pw3) == 0) {
pwmat = 0;
}
}
if (strcmp(idsol, id4) == 0) { //these 5 blocks!!!
idmat = 0;
if (strcmp(pwsol, pw4) == 0) {
pwmat = 0;
}
}
if (idmat != 0) {
printf("ID does not exist.\n");
i++;
idmat = 1;
}
else if (idmat == 0 && pwmat != 0) {
printf("PW does not match.\n");
i++;
idmat = 1;
} else {
logstack = 0;
break;
}
}
if (logstack >= 2) {
printf("login failed.\n");
} else {
printf("login successful!\n");
}
return 0;
}
Thanks for any comment! have a nice day
You should use arrays to gather the values to be used in loops.
#include <stdio.h>
#include <string.h>
int main(void) {
char id0[] = "user1";
char id1[] = "user2";
char id2[] = "user3";
char id3[] = "user4";
char id4[] = "user5";
char pw0[] = "pass1";
char pw1[] = "pass2";
char pw2[] = "pass3";
char pw3[] = "pass4";
char pw4[] = "pass5";
/* gather strings in arrays */
char* ids[] = { id0, id1, id2, id3, id4 };
char* pws[] = { pw0, pw1, pw2, pw3, pw4 };
char idsol[100] = { 0 };
char pwsol[100] = { 0 };
int idmat = 1;
int pwmat = 1;
int logstack = 0;
for (int i = 0; i <= 2;) {
logstack = i;
rewind(stdin);
printf("ID: ");
scanf_s("%s", idsol, sizeof(idsol));
printf("PW: ");
scanf_s("%s", pwsol, sizeof(pwsol));
/* use the arrays for looping */
for (int j = 0; j < 5; j++) {
if (strcmp(idsol, ids[j]) == 0) {
idmat = 0;
if (strcmp(pwsol, pws[j]) == 0) {
pwmat = 0;
}
}
}
if (idmat != 0) {
printf("ID does not exist.\n");
i++;
idmat = 1;
}
else if (idmat == 0 && pwmat != 0) {
printf("PW does not match.\n");
i++;
idmat = 1;
}
else { logstack = 0; break; }
}
if (logstack >= 2) {
printf("login failed.\n");
}
else { printf("login successful!\n"); }
return 0;
}
Another way is putting the string directly in arrays:
#include <stdio.h>
#include <string.h>
int main(void) {
char ids[][6] = {
"user1",
"user2",
"user3",
"user4",
"user5"
};
char pws[][6] = {
"pass1",
"pass2",
"pass3",
"pass4",
"pass5"
};
char idsol[100] = { 0 };
char pwsol[100] = { 0 };
/* omit: same as the first code */
}
I have just defined a function to do the looping and changed your array definitions into a list of strings. The code is below (follow the explanations in the code):
#include <stdio.h>
#include <string.h>
#define NTIMES 3 /* ask three times for a password */
/* this table organization allows you to iterate for each pair of ids[i]
* and pws[i]. */
char *ids[] = {
"user1",
"user2",
"user3",
"user4",
"user5",
NULL, /* to indicate we are finished this controls how the end of
* the list is reached below */
};
char *pws[] = {
"pass1",
"pass2",
"pass3",
"pass4",
"pass5", /* don't need to add a NULL here, but there
* must be as many entries as for used ids */
};
/* this function searches the two tables above for a valid user/pass match */
int check_user(char *user, char *pass)
{
int id;
for (id = 0; ids[id] != NULL; id++) { /* iterate the list */
if (0 == strcmp(ids[id], user)) { /* if user found */
if (0 == strcmp(pws[id], pass)) { /* if pass matches */
printf("Found user %d, id=%s\n", id, ids[id]);
return id; /* found user, return value of id to know
* outside which user was selected. */
} else {
printf("PW does not match\n");
/* we continue for the next pair in the loop */
}
}
}
/* we ended the loop without a valid user/pass match */
printf("ID %s does not exist, or password incorrect\n", user);
return -1; /* not found, we return a number out of the valid range */
}
int main(void) {
/* initializing these variables is not neccessary as you assign them
* (by reading into them from stdin) before using. But it is a good
* practice, so it is more difficult that you forget initializing
* variables that should have a default value. */
char idsol[100] = { 0 };
char pwsol[100] = { 0 };
// int idmat = 1; // unnecessary
// int pwmat = 1; // unnecessary
// int logstack = 0; // unnecessary
/* we need to declare times outside the for loop, because we are using
* the last value assigned to it in the loop, so in case we get out of
* the loop prematurely, we know we got a valid user. */
int times = -1; /* we initialize, for the same reason explained above */
for (times = 0; times < NTIMES; times++) {
// logstack = i; // unnecessary
// rewind(stdin); // unnecessary
printf("ID: ");
if (!fgets(idsol, sizeof idsol, stdin)) {
break; /* EOF on input, get out of the loop */
}
char *id_pointer = strtok(idsol, "\n"); /* take off the last
* newline */
// scanf_s("%s", idsol, sizeof(idsol)); // scanf_s is not standard
printf("PW: ");
if (!fgets(pwsol, sizeof pwsol, stdin)) {
break; /* EOF while reading input, get out of the loop */
}
char *pass_pointer = strtok(pwsol, "\n"); /* take off the newline */
// scanf_s("%s", pwsol, sizeof(pwsol)); // scanf_s is not standard
/* this calls the function above that tests a username/password
* and prints the messages in the block below */
if (check_user(id_pointer, pass_pointer) >= 0)
break; /* get out of the loop */
/* this was the code you wanted to eliminate, so here it is, commented */
// if (strcmp(idsol, id0) == 0) { //i want to make these 5 blocks in
// one command.
// idmat = 0;
// if (strcmp(pwsol, pw0) == 0) {
// pwmat = 0;
// }
// }
// if (strcmp(idsol, id1) == 0) {
// idmat = 0;
// if (strcmp(pwsol, pw1) == 0) {
// pwmat = 0;
// }
// }
// if (strcmp(idsol, id2) == 0) {
// idmat = 0;
// if (strcmp(pwsol, pw2) == 0) {
// pwmat = 0;
// }
// }
// if (strcmp(idsol, id3) == 0) {
// idmat = 0;
// if (strcmp(pwsol, pw3) == 0) {
// pwmat = 0;
// }
// }
// if (strcmp(idsol, id4) == 0) { //these 5 blocks!!!
// idmat = 0;
// if (strcmp(pwsol, pw4) == 0) {
// pwmat = 0;
// }
// }
// if (idmat != 0) {
// printf("ID does not exist.\n");
// i++;
// idmat = 1;
// }
// else if (idmat == 0 && pwmat != 0) {
// printf("PW does not match.\n");
// i++;
// idmat = 1;
// } else {
// logstack = 0;
// break;
// }
}
/* i have changed slightly this code also to use a single constant
* (by using its name, so i can modify the number of times to ask for
* a password, by editing only in one place (at the top). */
if (times < NTIMES) {
printf("login successful!\n");
return 0; /* successful exit code, see exit(3) for details */
} else {
printf("login failed.\n");
return 1; /* some error happened */
}
}

Why does SChannel TLS limit a message to 32kb

I am working on using SChannel to build a client/server program. One of the things I would like to do is have file sharing. I found some example code of a client program using Schannel to communicate and I am wondering why the max size of a message is 32kb. Here is the example function that does the receiving
int tls_handshake(tls_ctx *c, tls_session *s) {
DWORD flags_in, flags_out;
SecBuffer ib[2], ob[1];
SecBufferDesc in, out;
int len;
// send initial hello
if (!tls_hello(c, s)) {
return 0;
}
flags_in = ISC_REQ_REPLAY_DETECT |
ISC_REQ_CONFIDENTIALITY |
ISC_RET_EXTENDED_ERROR |
ISC_REQ_ALLOCATE_MEMORY |
ISC_REQ_MANUAL_CRED_VALIDATION;
c->ss = SEC_I_CONTINUE_NEEDED;
s->buflen = 0;
while (c->ss == SEC_I_CONTINUE_NEEDED ||
c->ss == SEC_E_INCOMPLETE_MESSAGE ||
c->ss == SEC_I_INCOMPLETE_CREDENTIALS)
{
if (c->ss == SEC_E_INCOMPLETE_MESSAGE)
{
// receive data from server
len = recv(s->sck, &s->buf[s->buflen], s->maxlen - s->buflen, 0);
// socket error?
if (len == SOCKET_ERROR) {
c->ss = SEC_E_INTERNAL_ERROR;
break;
// server disconnected?
} else if (len==0) {
c->ss = SEC_E_INTERNAL_ERROR;
break;
}
// increase buffer position
s->buflen += len;
}
// inspect what we've received
//tls_hex_dump(s->buf, s->buflen);
// input data
ib[0].pvBuffer = s->buf;
ib[0].cbBuffer = s->buflen;
ib[0].BufferType = SECBUFFER_TOKEN;
// empty buffer
ib[1].pvBuffer = NULL;
ib[1].cbBuffer = 0;
ib[1].BufferType = SECBUFFER_VERSION;
in.cBuffers = 2;
in.pBuffers = ib;
in.ulVersion = SECBUFFER_VERSION;
// output from schannel
ob[0].pvBuffer = NULL;
ob[0].cbBuffer = 0;
ob[0].BufferType = SECBUFFER_VERSION;
out.cBuffers = 1;
out.pBuffers = ob;
out.ulVersion = SECBUFFER_VERSION;
c->ss = c->sspi->
InitializeSecurityContextA(
&s->cc, &s->ctx, NULL, flags_in, 0,
SECURITY_NATIVE_DREP, &in, 0, NULL,
&out, &flags_out, NULL);
// what have we got so far?
if (c->ss == SEC_E_OK ||
c->ss == SEC_I_CONTINUE_NEEDED ||
(FAILED(c->ss) && (flags_out & ISC_RET_EXTENDED_ERROR)))
{
// response for server?
if (ob[0].cbBuffer != 0 && ob[0].pvBuffer) {
// send response
tls_send(s->sck, ob[0].pvBuffer, ob[0].cbBuffer);
// free response
c->sspi->FreeContextBuffer(ob[0].pvBuffer);
ob[0].pvBuffer = NULL;
}
}
// incomplete message? continue reading
if (c->ss==SEC_E_INCOMPLETE_MESSAGE) continue;
// completed handshake?
if (c->ss==SEC_E_OK) {
s->established = 1;
// If the "extra" buffer contains data, this is encrypted application
// protocol layer stuff and needs to be saved. The application layer
// will decrypt it later with DecryptMessage.
if (ib[1].BufferType == SECBUFFER_EXTRA) {
DEBUG_PRINT(" [ we have extra data after handshake.\n");
memmove(s->pExtra.pvBuffer,
&s->buf[(s->buflen - ib[1].cbBuffer)], ib[1].cbBuffer);
s->pExtra.cbBuffer = ib[1].cbBuffer;
s->pExtra.BufferType = SECBUFFER_TOKEN;
} else {
// no extra data encountered
s->pExtra.pvBuffer = NULL;
s->pExtra.cbBuffer = 0;
s->pExtra.BufferType = SECBUFFER_EMPTY;
}
break;
}
// some other error
if(FAILED(c->ss)) break;
// Copy any leftover data from the "extra" buffer, and go around again.
if(ib[1].BufferType == SECBUFFER_EXTRA) {
memmove(s->buf, &s->buf[(s->buflen - ib[1].cbBuffer)], ib[1].cbBuffer);
s->buflen = ib[1].cbBuffer;
DEBUG_PRINT(" [ we have %i bytes of extra data.\n", s->buflen);
tls_hex_dump(s->buf, s->buflen);
} else {
s->buflen = 0;
}
}
return c->ss==SEC_E_OK ? 1 : 0;
}
The code comes from a Github I found here: https://github.com/odzhan/shells/blob/master/s6/tls.c
Inside one of his header files he defines
#define TLS_MAX_BUFSIZ 32768
I have also read in other places that this is a limit with TLS. Is it possible to increase that limit? What happens if I need to receive more then that? Like a large file?

Double buffering and printf

I am having trouble with getting my other basic functions to work with double buffer.
for example in the code below, it runs and I can press either down or up to move my cursor, and when I press enter I am supposed to get a printf saying either making a new char, load, or goodbye.
It shows up for a split second but then it immediately disappears. In these situations rewind(stdin) and getchar(); solves this issue but for this code, nothing seems to work.
Please help.
#define _CRT_SECURE_NO_WARNINGS
#include "conioex.h"
#include "DblBuffer.h"
enum //
{
NEW_GAME = 20,
LOAD,
EXIT,
MAX_NUM
};
void main (void)
{
DblBuffer db;
int Cursor_X, Cursor_Y; // cursorlocation
bool Key_flag = false; // pressandtrue
int type = NEW_GAME; // type
Cursor_X = 20;
Cursor_Y = 1;
int flag = 1;
while (flag)
{
for (int i = 1; i <= 3; i++)
{
db.setCursorPos(20,i);
db.write(" ");
}
db.setCursorPos(25,1);
db.write("New Game\n");
db.setCursorPos(25,2);
db.write("Load\n");
db.setCursorPos(25,3);
db.write("Exit\n");
if (inport(PK_DOWN))
{
if (Key_flag == false)
{
Cursor_Y = Cursor_Y + 1;
type = type + 1;
Key_flag = true;
}
}
else if (inport(PK_UP))
{
if (Key_flag == false)
{
Cursor_Y = Cursor_Y - 1;
type = type - 1;
Key_flag = true;
}
}
else if (inport(PK_ENTER))
{
flag = 0;
break;
}
else
{
Key_flag = false;
}
if (Cursor_Y < 1)
{
Cursor_Y = 1;
}
if (Cursor_Y > 3)
{
Cursor_Y = 3;
}
if (type < NEW_GAME)
{
type = NEW_GAME;
}
if (type >= MAX_NUM)
{
type = MAX_NUM - 1;
}
db.setCursorPos(Cursor_X, Cursor_Y);
db.write("→");
db.swap();
}
if(type == NEW_GAME)
{
printf("making a new game");
}
if (type == LOAD)
{
printf("will load");
}
if (type == EXIT)
{
printf("goodbye");
}
rewind(stdin);
getchar();
}
As for your problem, by "then it immediately disappears" I assume that the console window disappears quickly?
That's because the program exits.
You need to flush the input buffer connected to stdin to remove all key presses you made (by reading from stdin) and then call getchar one extra time to get a a kind of confirmation that the user wants to exit.

Allocation of buffer in C

I am trying to create buffer to store infinity size of symbols.
I have this structure:
typedef struct buffer {
int bufferSize;
int literalSize;
int allocatedSize;
char *bufferPtr;
} bufferStruct;
In my file.h.
I have also functions for buffer:
bufferStruct *BufferInitialize(int size) {
bufferStruct *tempBuff;
tempBuff = (bufferStruct *)malloc(sizeof(bufferStruct));
if (tempBuff == NULL) {
exit(99); // MEMORY_ERROR
}
tempBuff->bufferSize = size;
tempBuff->literalSize = 0;
tempBuff->bufferPtr = NULL;
tempBuff->allocatedSize = 0;
return (tempBuff);
}
int addToBuffer(bufferStruct *buffer, char c) {
if (buffer == NULL) {
return 99; // MEMORY_ERROR
}
if (buffer->allocatedSize > buffer->literalSize) {
buffer->bufferPtr[buffer->literalSize++] = c;
} else {
buffer->bufferPtr = realloc(buffer->bufferPtr, (buffer->allocatedSize + buffer->bufferSize) * sizeof(char));
if (buffer->bufferPtr == NULL) {
return 99; // MEMORY_ERROR
}
buffer->allocatedSize += buffer->bufferSize;
buffer->bufferSize <<= 1; // bS = bS * 2
buffer->bufferPtr[buffer->literalSize++] = c;
}
return 0;
}
int bufferDestroy(bufferStruct *buffer) {
if (buffer == NULL) {
return 99; // MEMORY_ERROR
}
free(buffer->bufferPtr);
free(buffer);
return 0;
}
In my file.c I am trying to create buffer:
token *getNextToken(token *tokenT) {
token *actualToken = NULL;
char *bufferData = NULL;
int charFromFile;
eState state = stateInit;
bufferStruct *bufferT = NULL;
while ((charFromFile = fgetc(fp))) {
switch (state) {
case stateInit: {
if (isdigit(charFromFile)) {
bufferT = BufferInitialize(8);
addToBuffer(bufferT, charFromFile);
state = stateInt;
} else
if (isalpha(charFromFile) || (charFromFile == '_')) {
state = stateId;
bufferT = BufferInitialize(16);
addToBuffer(bufferT, charFromFile);
} else
if (isspace(charFromFile)) {
state = stateInit;
... some more conditions ... it's similar, a lot.
case stateInt: {
if (isdigit(charFromFile)) {
state = stateInt;
addToBuffer(bufferT, charFromFile);
} else
if ((charFromFile == 'e') || (charFromFile == 'E')) {
state = stateExp;
addToBuffer(bufferT, charFromFile);
} else
if (charFromFile = '.') {
state = stateDouble;
addToBuffer(bufferT, charFromFile);
} else {
bufferData = bufferT->bufferPtr;
//strcpy(actualToken->content, bufferData);
addToBuffer(bufferT, '\0');
bufferDestroy(bufferT);
actualToken->type = tokenInt;
return actualToken;
}
} break;
... other similar cases ...
}
}
}
The problem is when I am trying to do this, Visual studio give me error:
One or more multiply defined symbols found
Also gives me
already defined in main.obj
for every function I have.
I don't see the way out. What am I doing wrong ?
There are multiple issues in your code:
You should not put code in header files. The function BufferInitialize should not be located in file.h unless it is defined inline.
The test while (c = fgetc(fp)) is incorrect: you use an assignment as a test expression, it is very error prone, you should at least parenthesize the assignment expression, and probably test for EOF instead of '\0': while ((c = fgetc(fp)) != EOF). Furthermore, c must be defined as an int. Post actual code, not pseudo-code.
You initialize tempBuff->bufferSize to a potentially non zero value, whereas the allocatedSize is 0 and the buffer is unallocated. This seems incorrect.
There could be many more issues in your actual code, we cannot see what the code, how can be tell you about those? Always post a complete, compilable code that demonstrates the problem.

Populating datagrid from serialport

I am working on a program that is a decoder, it reads from an interface connected through the serial port and I am then interpreting the information and putting it into a datagrid. I am having a problem where not all of the information is getting transferred into the datagrid, but I'm not sure why.
// Declare a delegate for method DoUpdate().
private delegate void MethodDelegate();
private MethodDelegate ReadSerialData;
bool loggerRunning;
private void button1_Click(object sender, RoutedEventArgs e)
{
if (!loggerRunning)
{
// Delegate for DoUpdate.
ReadSerialData = new MethodDelegate(DoUpdate);
//Create new serialport.
Sp = new SerialPort();
//Set the appropriate properties.
Sp.PortName = SetPortName(Sp.PortName);
Sp.BaudRate = SetBaudRate(Sp.BaudRate);
Sp.Parity = Parity.None;
Sp.DataBits = SetDataBits(Sp.DataBits);
Sp.StopBits = StopBits.One;
Sp.Handshake = Handshake.None;
Sp.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
Sp.Open();
loggerRunning = true;
}
else
{
Sp.Close();
loggerRunning = false;
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Dispatcher.Invoke(DispatcherPriority.Normal, ReadSerialData);
}
private List<IEBusData> sortedData = new List<IEBusData>();
// Process received data.
// Via delegate ReadSerialData.
private void DoUpdate()
{
string[] tempRow = new string[35];
try
{
do
{
try
{
String Temp = Sp.ReadByte().ToString("X"); // Read from Input Buffer
Byte_Read++;
if ((Temp == "7B") && (Rx_State != HDR0 || Rx_State != Rx_Data))
{
Rx_State = HDR0;
}
switch (Rx_State)
{
case HDR0: // Check for Header byte 0
// Check to see if matches Header0
if (Temp == "7B")
{ Rx_State++; }
break;
case HDR1: // Check for Header byte 1
if (Temp == "7D")
{
Rx_State++;
}
else
{ Rx_State = HDR0; }
break;
case MSTR_ADDR: // Clock in Master Address
MASTER += Temp;
if (MASTER.Length == 3) // Master Address is 3 bytes
{ Rx_State++; }
break;
case SLVE_ADDR: // Clock in Slave Address
SLAVE += Temp;
if (SLAVE.Length == 3) // Slave Address is 3 bytes
{
tempRow[0] = MASTER; // Put Master Address into Grid
tempRow[1] = SLAVE; // Put Slave Address into Grid
Rx_State++; // Move to next Receive State
MASTER = ""; // Reset MASTER
SLAVE = ""; // Reset SLAVE
}
break;
case Rx_Len: // Clock in Message Length
Length = Convert.ToInt16(Temp, 16); // Convert Length back to Hex digit
if (Length <= 0x20)
{
if (Temp.Length == 1)
{
tempRow[2] = "0" + Temp;
}
else
{
tempRow[2] = Temp;
}
Rx_State++;
}
else if (Length == 0x7B)
{ Rx_State = HDR1; }
else if (Length == 0x7D)
{ Rx_State = MSTR_ADDR; }
else
{ Rx_State = HDR0; }
break;
case Rx_Data: // Clock in Data Bytes
if (Temp.Length == 1)
{
tempRow[Data_Column] = "0" + Temp;
}
else
{
tempRow[Data_Column] = Temp;
}
Length--;
Data_Column++;
if (Length < 1) // If all data Received
{
Rx_State = HDR0; // Reset Receive State
Data_Column = 3; // Reset Columns
Curr_Row++; // Increment Row Number
sortedData.Add(new IEBusData(tempRow));
dgIEBus.ItemsSource = sortedData;
dgIEBus.Items.Refresh();
}
break;
default:
break;
}
// this.Update();
}
catch (SystemException)
{ }
} while (Sp.BytesToRead > Byte_Read);
Byte_Read = 0;
}
catch (InvalidOperationException) { }
}
}

Resources