Ok here's a update on all the code I have so far.
It appears to send data but once it gets to the 2nd time around it gives a exception error in vb.net
#include "config.h"
#include "IKSClient.h"
#define OWN_TASK TASK_IKS_CLIENT
#define INITIALISATION 0
#define ACTIVE 1
// TCP Settings
int connected = 0;
int busy = 0;
#define IKS_SERVER_PORT 8000
static USOCKET iks_client_socket;
static unsigned char iks_server_ip[IPV4_LENGTH] = {192, 168, 1, 69};
#define MAX_DATA_LEN 100
typedef struct stTCP_MESSAGE
{
TCP_HEADER tTCP_Header; // reserve header space
unsigned char ucTCP_Message[MAX_DATA_LEN]; // data payload space
} TCP_MESSAGE;
static TCP_MESSAGE IKSData;
// Serial Port Settings
int iSerialRxLenth = 0;
static unsigned char ucSerialInput[RX_BUFFER_SIZE];
QUEUE_HANDLE SerialPortID = 0;
static int fnIKSListener(USOCKET Socket, unsigned char ucEvent, unsigned char *ucIp_Data, unsigned short usPortLen)
{
switch (ucEvent) {
case TCP_EVENT_CONNECTED:
connected = 1;
memcpy(IKSData.ucTCP_Message,ucSerialInput,iSerialRxLenth);
if(fnSendTCP(iks_client_socket, (unsigned char *)&IKSData.tTCP_Header, iSerialRxLenth, TCP_FLAG_PUSH) > 0)
return APP_SENT_DATA;
break;
case TCP_EVENT_ARP_RESOLUTION_FAILED:
break;
case TCP_EVENT_REGENERATE:
memcpy(IKSData.ucTCP_Message,ucSerialInput,iSerialRxLenth);
if(fnSendTCP(iks_client_socket, (unsigned char *)&IKSData.tTCP_Header, iSerialRxLenth, TCP_FLAG_PUSH) > 0)
return APP_SENT_DATA;
break;
case TCP_EVENT_DATA:
busy = 0;
break;
case TCP_EVENT_CLOSE:
case TCP_EVENT_CLOSED:
connected = 0;
break;
case TCP_EVENT_ACK:
connected = 1;
uTaskerStateChange(OWN_TASK, UTASKER_ACTIVATE);
break;
case TCP_EVENT_ABORT:
fnTCP_Connect(iks_client_socket, iks_server_ip, IKS_SERVER_PORT, 0, 0);
break;
}
return APP_ACCEPT;
}
static int fnReadIrd(unsigned char * buf)
{
static int iRxReceived = 0; // the number of byte received (until now)
static int iExpectedbytes = 0;
unsigned char ucInputMessage; // reserve space for receiving messages
while (fnRead(SerialPortID, &ucInputMessage, 1) != 0) { // read each presently available input byte
if (iRxReceived == 0) { // searching for sync byte
if (ucInputMessage != 0x21) {
continue; // still not found sync byte
}
iRxReceived = 1; // synchronised
buf[0] = ucInputMessage;
}
else {
if (iRxReceived >= RX_BUFFER_SIZE) { // protect buffer overrun on invalid frames
iRxReceived = iExpectedbytes = 0; // go back to sync hunt mode
continue;
}
buf[iRxReceived++] = ucInputMessage; // collect message content
if (iRxReceived == 3) { // the expected length is now known
iExpectedbytes = (ucInputMessage + 4); // note the expected length
}
if (iRxReceived == iExpectedbytes) { // the complete message has now been collected
return iExpectedbytes; // inform of the frame length so that it can be processed
}
}
}
return -1; // frame not yet ready
}
// This task is started once to initialise the interface and then for each received character
//
extern void fnIKSClient(TTASKTABLE *ptrTaskTable)
{
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
if (!SerialPortID) { // configure interfaces on initialisation
SerialPortID = fnSetNewSerialMode(FOR_I_O);
iks_client_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, TCP_DEFAULT_TIMEOUT, fnIKSListener);
}
if (connected >= 2) { // TCP transmission is busy so wait - queue all UART rx data in UART buffer in the meantime
return;
}
while ((iSerialRxLenth = fnReadIrd(ucSerialInput)) != -1) { // collect the data until ready
memcpy(IKSData.ucTCP_Message,ucSerialInput,iSerialRxLenth);
if(!connected){
fnTCP_Connect(iks_client_socket, iks_server_ip, IKS_SERVER_PORT, 0, 0);
connected = 2;
} else {
fnSendTCP(iks_client_socket, (unsigned char *)&IKSData.tTCP_Header, iSerialRxLenth, TCP_FLAG_PUSH);
connected = 3;
}
break;
}
// else quit - we return on further input
}
// After changes, we set up the new serial configuration
// (moved from application.c to here) - in application.s #undef SERIAL_INTERFACE added to remove its control of the serial interface
extern QUEUE_HANDLE fnSetNewSerialMode(unsigned char ucDriverMode)
{
TTYTABLE tInterfaceParameters; // table for passing information to driver
tInterfaceParameters.Channel = DEMO_UART; // set UART channel for serial use
tInterfaceParameters.ucSpeed = temp_pars->temp_parameters.ucSerialSpeed; // baud rate
tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE; // input buffer size
tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE; // output buffer size
tInterfaceParameters.Task_to_wake = OWN_TASK; // wake self when messages have been received
#ifdef SUPPORT_FLOW_HIGH_LOW
tInterfaceParameters.ucFlowHighWater = temp_pars->temp_parameters.ucFlowHigh;// set the flow control high and low water levels in %
tInterfaceParameters.ucFlowLowWater = temp_pars->temp_parameters.ucFlowLow;
#endif
tInterfaceParameters.usConfig = temp_pars->temp_parameters.usSerialMode;
#ifdef SERIAL_SUPPORT_DMA
tInterfaceParameters.ucDMAConfig = UART_TX_DMA; // activate DMA on transmission
#endif
if ((SerialPortID = fnOpen( TYPE_TTY, ucDriverMode, &tInterfaceParameters )) != 0) { // open or change the channel with defined configurations (initially inactive)
fnDriver( SerialPortID, ( TX_ON | RX_ON ), 0 ); // enable rx and tx
}
return SerialPortID;
}
BTW I appreciate all the time and effort your putting into this for me and others.
Thanks!!!