Using COM1
Hello guys. I want made an electric circuit, you can see it in the image below. I connected it to COM1. I made a program that reads from COM1, but it reads only 0. I also tried with a serial mouse, and the program worked. So, the circuit is the problem. Please help.
Does your com1 device interface with the the port properly, how are you doing this.
I did a project at uni that involved messaging between computers throught the coms, have you opened and set teh port attributes properly for the port?
I did a project at uni that involved messaging between computers throught the coms, have you opened and set teh port attributes properly for the port?
I'll paste here some code:
HANDLE g_COM1;
char g_buffer[1024];
DWORD n;
INITIALIZATION:
DCB config;
COMMTIMEOUTS comTimeOut;
g_COM1 = CreateFile("COM1", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
GetCommState(g_COM1, &config);
config.BaudRate = 9600;
config.StopBits = 0;
config.Parity = 0;
config.ByteSize = 8;
SetCommState(g_COM1, &config);
comTimeOut.ReadIntervalTimeout = 3;
comTimeOut.ReadTotalTimeoutMultiplier = 3;
comTimeOut.ReadTotalTimeoutConstant = 2;
comTimeOut.WriteTotalTimeoutMultiplier = 3;
comTimeOut.WriteTotalTimeoutConstant = 2;
SetCommTimeouts(g_COM1,&comTimeOut);
READING:
ReadFile(g_COM1, g_buffer, 1024, &n, NULL);
When I print g_buffer, and using a remote control that points to FT, I get only 0. It works with a serial mouse. I also opened the mouse and pointed with the remote control inside it, and it works.
HANDLE g_COM1;
char g_buffer[1024];
DWORD n;
INITIALIZATION:
DCB config;
COMMTIMEOUTS comTimeOut;
g_COM1 = CreateFile("COM1", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
GetCommState(g_COM1, &config);
config.BaudRate = 9600;
config.StopBits = 0;
config.Parity = 0;
config.ByteSize = 8;
SetCommState(g_COM1, &config);
comTimeOut.ReadIntervalTimeout = 3;
comTimeOut.ReadTotalTimeoutMultiplier = 3;
comTimeOut.ReadTotalTimeoutConstant = 2;
comTimeOut.WriteTotalTimeoutMultiplier = 3;
comTimeOut.WriteTotalTimeoutConstant = 2;
SetCommTimeouts(g_COM1,&comTimeOut);
READING:
ReadFile(g_COM1, g_buffer, 1024, &n, NULL);
When I print g_buffer, and using a remote control that points to FT, I get only 0. It works with a serial mouse. I also opened the mouse and pointed with the remote control inside it, and it works.
ok well im gonna post the entire program i wrote at uni for you to have a look at, it was a message communication program for a ring network,m hope it helps
PS rating boost methinks :P
regards
ace
////////////////////////////////////////////////////////////////////////////////////////// Name: Ring Network Instant Messenger//// File: MAIN.cpp//// Date: 31st March 2004//// Auth: David Lovegrove//// Desc: This is a simple program that can transmit messages to any particular//// user that is logged in to the ring network. A copy of this program//// must be running for every computer wired in to the network although no//// user has to be logged on because all messages are forwarded.//// Advc: Currently the menu options have to be entered correctly. No error //// handling for the menus is functional.//////////////////////////////////////////////////////////////////////////////////////#include <stdio.h>#include <sys/types.h>#include <conio.h>#include <ctype.h>#include <windows.h>#include <winbase.h>// stores the ID of the loval userchar LocalUserID;// stores the id of everyone who is onlinechar OnlineUserArray[26];// Some global flags to keep track of various non-state operationsbool PacketToSend = false;bool LocalUserLoggedIn = false;bool SendLoggedInMessage = false;bool SendLogInAcknowledgement = false;bool SendLoggedOutMessage = false;bool SendDataMessage = false;bool SendMessageAcknowledgement = false;bool SendGenericPacket = false;bool DisplayFullPacketContents = false;bool ExtendedMessaging = false;bool MenuBeingUsed = false;HANDLE hComPort;DWORD dwError;char RecipientOfAck;char RecipientOfNextMsg;char MessageToSendArray[10];// A buffer of 10 DPacket copieschar LastDPacketSent[10][16];// A structure that will form an array to store recieved messages so that theycan be printed// to the screen after every menu has been displayedstruct PACKETBUFFER{ bool DisplayMessage; char bPacket[16];};// the arrayPACKETBUFFER mBuffer[10];// A structure that will forma an array to store messages that have return a nack// Define some global states and a state tracking variable//KeyBoard States#define KEYLOGGEDIN 1#define KEYLOGGEDOUT 2//Transmit States#define TRANSMITTING 1#define NOTTRANSMITTING 2//Recieve States#define RECIEVING 1#define NOTRECIEVING 2int KeyBoardStateTracker = KEYLOGGEDOUT;int TransmitStateTracker = TRANSMITTING;int RecieveStateTracker = RECIEVING;bool DrawOnMenu = true;bool DrawOffMenu = true;char InPacket[16];char OutPacket[16];int iPacketArrayMember;void menuLoggedIn();bool DisplayBufferContents(){ int i; int j; for (i = 0; i < 10; i++) { if (mBuffer.DisplayMessage == true) { printf("\t%c Says : ", mBuffer.bPacket[2]); if (DisplayFullPacketContents == true) { for (j = 0; j < 16; j++) { printf("%c", mBuffer.bPacket[j]); } } else { for (j = 4; j < 14; j++) { printf("%c", mBuffer.bPacket[j]); } } printf("\n"); } else { printf("\n"); } } return true;}bool InitialiseBuffer(){ int i,j; for (i = 0; i < 10; i++) { // a check will be performed on this variable and the message will not be // displayed if the contents of the Display variable is mBuffer.DisplayMessage = false; // clear the packet data for (j = 0; i < 16; i++) { mBuffer.bPacket[j] = ' '; } } return true;}bool AddNewMessageToBuffer(){ // code to loop through the message buffer and select the next place to enter a message // first see if the buffer is full int bufferCount = 0; bool FoundNextEmpty = false; int ElementToUseID = 0; for (int i = 0; i < 10; i++) { if (mBuffer.DisplayMessage == true) { bufferCount++; } } // Test the bufferFull variable and act according to putting the new message in the next // empty slot or shifting them all along and putting it into the first if (bufferCount != 10) { // loop through to find next enpty one for (i = 0; i < 10; i++) { if (FoundNextEmpty == false) { if (mBuffer.DisplayMessage == false) { // found the next empty one ElementToUseID = i; mBuffer.DisplayMessage = true; i = 0; FoundNextEmpty = true; } } } if (FoundNextEmpty == true) { // manual copy for the time being mBuffer[ElementToUseID].bPacket[0] = InPacket[0]; mBuffer[ElementToUseID].bPacket[1] = InPacket[1]; mBuffer[ElementToUseID].bPacket[2] = InPacket[2]; mBuffer[ElementToUseID].bPacket[3] = InPacket[3]; mBuffer[ElementToUseID].bPacket[4] = InPacket[4]; mBuffer[ElementToUseID].bPacket[5] = InPacket[5]; mBuffer[ElementToUseID].bPacket[6] = InPacket[6]; mBuffer[ElementToUseID].bPacket[7] = InPacket[7]; mBuffer[ElementToUseID].bPacket[8] = InPacket[8]; mBuffer[ElementToUseID].bPacket[9] = InPacket[9]; mBuffer[ElementToUseID].bPacket[10] = InPacket[10]; mBuffer[ElementToUseID].bPacket[11] = InPacket[11]; mBuffer[ElementToUseID].bPacket[12] = InPacket[12]; mBuffer[ElementToUseID].bPacket[13] = InPacket[13]; mBuffer[ElementToUseID].bPacket[14] = InPacket[14]; mBuffer[ElementToUseID].bPacket[15] = InPacket[15]; mBuffer[ElementToUseID].DisplayMessage = true; // set i to 10 so that it drops out on the next iteration } } else if (bufferCount == 10) { // code to rotate the buffer so that a space at the front is created // and the bottom element is lost mBuffer[0] = mBuffer[1]; mBuffer[1] = mBuffer[2]; mBuffer[2] = mBuffer[3]; mBuffer[3] = mBuffer[4]; mBuffer[4] = mBuffer[5]; mBuffer[5] = mBuffer[6]; mBuffer[6] = mBuffer[7]; mBuffer[7] = mBuffer[8]; mBuffer[8] = mBuffer[9]; mBuffer[9] = mBuffer[0]; // now place the new message in element 0 mBuffer[9].bPacket[0] = InPacket[0]; mBuffer[9].bPacket[1] = InPacket[1]; mBuffer[9].bPacket[2] = InPacket[2]; mBuffer[9].bPacket[3] = InPacket[3]; mBuffer[9].bPacket[4] = InPacket[4]; mBuffer[9].bPacket[5] = InPacket[5]; mBuffer[9].bPacket[6] = InPacket[6]; mBuffer[9].bPacket[7] = InPacket[7]; mBuffer[9].bPacket[8] = InPacket[8]; mBuffer[9].bPacket[9] = InPacket[9]; mBuffer[9].bPacket[10] = InPacket[10]; mBuffer[9].bPacket[11] = InPacket[11]; mBuffer[9].bPacket[12] = InPacket[12]; mBuffer[9].bPacket[13] = InPacket[13]; mBuffer[9].bPacket[14] = InPacket[14]; mBuffer[9].bPacket[15] = InPacket[15]; } return false;}////////////////////////////////////////////////////////////////////////////////////////// Name: InitiatePort()//// Params: char *device//// Desc: This funcion initialises the com port with the name passed to it from//// main() vis the *device parameter. This function makes all input non-//// blocking.//////////////////////////////////////////////////////////////////////////////////////bool InitiatePort(char *device){ COMMTIMEOUTS noblock; DCB dcb; int fSuccess; hComPort=CreateFile(device,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if (hComPort == INVALID_HANDLE_VALUE) { dwError = GetLastError(); printf("INVALID_HANDLE_VALUE()"); } fSuccess = GetCommTimeouts(hComPort, &noblock); noblock.ReadTotalTimeoutConstant = 1; noblock.ReadTotalTimeoutMultiplier = MAXDWORD; noblock.ReadIntervalTimeout = MAXDWORD; fSuccess=SetCommTimeouts(hComPort,&noblock); fSuccess = GetCommState(hComPort, &dcb); if(!fSuccess) { printf("GetCommState Error!\n"); return false; } dcb.BaudRate = 9600; dcb.ByteSize = 7; dcb.fParity = TRUE; dcb.Parity = EVENPARITY; dcb.StopBits = TWOSTOPBITS; dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fOutxCtsFlow = TRUE; fSuccess = SetCommState(hComPort, &dcb); if(!fSuccess) { printf("SetCommState Error!\n"); return false; } return true;}////////////////////////////////////////////////////////////////////////////////////////// Name: ClearPacketArrays()//// Params: NONE//// Desc: Is called from main during initialisation and is used to clear all//// packets and fill them with blank spaces.//////////////////////////////////////////////////////////////////////////////////////int ClearPacketArrays(){ int count; for (count = 0; count < 17; count++) { InPacket[count] = ' '; OutPacket[count] = ' '; } return 1;}////////////////////////////////////////////////////////////////////////////////////////// Name: ReadCom()//// Params: NONE//// Desc: Reads the next single character from the com port.//////////////////////////////////////////////////////////////////////////////////////int ReadCom(){ char item; unsigned long ni; BOOL fsuccess; fsuccess = ReadFile(hComPort,&item,1,∋,NULL); if (ni == 1) return item; else return 0;}////////////////////////////////////////////////////////////////////////////////////////// Name: DisplayMessageFromPacket()//// Params: NONE//// Desc: Called by the dissassemble packet function once the type of packet recieved//// has been identified. Depending on the menu option "4. Display Full //// Packet Contents -" can display the entire packet or just the message.//////////////////////////////////////////////////////////////////////////////////////void DisplayMessageFromPacket(){/* int i; printf("\n%c Says : ", InPacket[2]); if (DisplayFullPacketContents == true) { for (i = 0; i < 16; i++) { printf("%c", InPacket); } } else for (i = 4; i < 14; i++) { printf("%c", InPacket); } printf("\n");*/}////////////////////////////////////////////////////////////////////////////////////////// Name: ForwardPacket()//// Params: NONE//// Desc: Called by the dissassemble packet function once the type of packet recieved//// has been identified. Is used to copy the packet recieved to the packet//// ready to be sent.//////////////////////////////////////////////////////////////////////////////////////void ForwardPacket(){ OutPacket[0] = '{'; OutPacket[1] = InPacket[1]; OutPacket[2] = InPacket[2]; OutPacket[3] = InPacket[3]; OutPacket[4] = InPacket[4]; OutPacket[5] = InPacket[5]; OutPacket[6] = InPacket[6]; OutPacket[7] = InPacket[7]; OutPacket[8] = InPacket[8]; OutPacket[9] = InPacket[9]; OutPacket[10] = InPacket[10]; OutPacket[11] = InPacket[11]; OutPacket[12] = InPacket[12]; OutPacket[13] = InPacket[13]; OutPacket[14] = InPacket[14]; OutPacket[15] = '}';}////////////////////////////////////////////////////////////////////////////////////////// Name: DisassemblePacket()//// Params: NONE//// Desc: Once a packet has been fully recieved in DealWithRecievedCharacter(),//// this function is called to opereate according to the type of packet.//// Is also used to control the application of the ExtendedMessaging function.//////////////////////////////////////////////////////////////////////////////////////void DisassemblePacket(){ int converted; if ( InPacket[3] == 'L') { if (LocalUserLoggedIn == true) { if (ExtendedMessaging == true) DisplayMessageFromPacket(); if (MenuBeingUsed == false) { menuLoggedIn(); } if (InPacket[1] == LocalUserID) { // by doing nothing here, the packet is not being forwarded so is effectively // being deleted } else { // convert to ascii value converted = (int) toupper(InPacket[1]); // Fill user log in table for appropriate user OnlineUserArray[(converted-65)] = InPacket[1]; // Send an acknowledgement packet SendLogInAcknowledgement = true; // Forward the packet ForwardPacket(); SendGenericPacket = true; // Code to add the recieved message to the buffer AddNewMessageToBuffer(); } } else { ForwardPacket(); SendGenericPacket = true; } } else if( InPacket[3] == 'R') { if (LocalUserLoggedIn == true) { if (ExtendedMessaging == true) DisplayMessageFromPacket(); if (InPacket[1] == LocalUserID) { // convert to ascii value converted = (int) toupper(InPacket[2]); // Fill user log in table for appropriate user OnlineUserArray[(converted-65)] = InPacket[2]; } else { ForwardPacket(); // Code to add the recieved message to the buffer AddNewMessageToBuffer(); SendGenericPacket = true; } // Tell the transmitting loop to send it on if (MenuBeingUsed == false) { menuLoggedIn(); } } else { ForwardPacket(); SendGenericPacket = true; } } else if( InPacket[3] == 'X') { if (LocalUserLoggedIn == true) { if (ExtendedMessaging == true) DisplayMessageFromPacket(); if (InPacket[1] != LocalUserID) { AddNewMessageToBuffer(); // convert to ascii value converted = (int) toupper(InPacket[1]); // Fill user log in table for appropriate user OnlineUserArray[(converted-65)] = '_'; // forward the login packet on ForwardPacket(); SendGenericPacket = true; } if (MenuBeingUsed == false) { menuLoggedIn(); } } else { ForwardPacket(); SendGenericPacket = true; } } else if( InPacket[3] == 'D') { if (LocalUserLoggedIn == true) { // Check to see if i'm the recipient if (InPacket[1] == LocalUserID) { AddNewMessageToBuffer(); // Data payload packet ie a message to be displayed to the screen // Then send an acknowledgement packet to the author DisplayMessageFromPacket(); // Set the global variable that will hold the recipient of the acknowledgemnt packet RecipientOfAck = InPacket[2]; SendMessageAcknowledgement = true; } else { // Construct a copy of the recieved packet to forward on ForwardPacket(); SendGenericPacket = true; // Tell the transmitting loop to send it on } // now update the menu providing it isnt being used. if (MenuBeingUsed == false) { menuLoggedIn(); } } else { SendGenericPacket = true; ForwardPacket(); } }}////////////////////////////////////////////////////////////////////////////////////////// Name: DealWithRecievedCharacter()//// Params: char iInCharacter, bool *RunFlag//// Desc: Every time readcom() finds a character on the com port this function //// is called to detect the start and end of packets.//////////////////////////////////////////////////////////////////////////////////////bool DealWithRecievedCharacter(char iInCharacter, bool *RunFlag){ if (iInCharacter != 0) { if (iInCharacter == '{') { iPacketArrayMember = 0; InPacket[iPacketArrayMember] = iInCharacter; iPacketArrayMember++; } else { InPacket[iPacketArrayMember] = iInCharacter; iPacketArrayMember++; if (iInCharacter == '}') return true; } } else { } return false;}////////////////////////////////////////////////////////////////////////////////////////// Name: CompilePacketToSend()//// Params: char PacketType//// Desc: Every time a packet needs to be sent for any reason this fuinction is//// called and the packet type that is described to it using the parameter//// is constructed.//////////////////////////////////////////////////////////////////////////////////////int CompilePacketToSend(char PacketType){ if (PacketType == 'L') { OutPacket[0] = '{'; OutPacket[1] = LocalUserID; OutPacket[2] = LocalUserID; OutPacket[3] = PacketType; char string[11] = "Logged In "; strcpy(&OutPacket[4],string); OutPacket[14] = '#'; OutPacket[15] = '}'; } else if (PacketType == 'X') { OutPacket[0] = '{'; OutPacket[1] = LocalUserID; OutPacket[2] = LocalUserID; OutPacket[3] = PacketType; char string[11] = "Logged Out"; strcpy(&OutPacket[4],string); OutPacket[14] = '#'; OutPacket[15] = '}'; } else if (PacketType == 'R') { OutPacket[0] = '{'; OutPacket[1] = InPacket[2];; OutPacket[2] = LocalUserID; OutPacket[3] = PacketType; char string[11] = "LOGIN ACK "; strcpy(&OutPacket[4],string); OutPacket[14] = '#'; OutPacket[15] = '}'; } else if (PacketType == 'D') { OutPacket[0] = '{'; OutPacket[1] = RecipientOfNextMsg; OutPacket[2] = LocalUserID; OutPacket[3] = PacketType; OutPacket[4] = MessageToSendArray[0]; OutPacket[5] = MessageToSendArray[1]; OutPacket[6] = MessageToSendArray[2]; OutPacket[7] = MessageToSendArray[3]; OutPacket[8] = MessageToSendArray[4]; OutPacket[9] = MessageToSendArray[5]; OutPacket[10] = MessageToSendArray[6]; OutPacket[11] = MessageToSendArray[7]; OutPacket[12] = MessageToSendArray[8]; OutPacket[13] = MessageToSendArray[9]; OutPacket[14] = '#'; OutPacket[15] = '}'; } else if (PacketType == 'Y') { OutPacket[0] = '{'; OutPacket[1] = InPacket[2]; OutPacket[2] = LocalUserID; OutPacket[3] = PacketType; char string[11] = "+ ACK "; strcpy(&OutPacket[4],string); OutPacket[14] = '#'; OutPacket[15] = '}'; } else if (PacketType == 'N') { OutPacket[0] = '{'; OutPacket[1] = RecipientOfNextMsg; OutPacket[2] = LocalUserID; OutPacket[3] = PacketType; char string[11] = "- ACK "; strcpy(&OutPacket[4],string); OutPacket[14] = '#'; OutPacket[15] = '}'; } return 1;}////////////////////////////////////////////////////////////////////////////////////////// Name: SendPacket()//// Params: char PacketType//// Desc: After the packet that needs to be sent has been constructed using the//// above function, this functions is called to push the packet to the port//////////////////////////////////////////////////////////////////////////////////////int SendPacket(){ unsigned long ni; BOOL fSuccess; fSuccess = WriteFile(hComPort,OutPacket,16,∋,NULL); if (ni == 16 ) return 0; else return 1;}////////////////////////////////////////////////////////////////////////////////////////// Name: LogOut()//// Params: bool *pRunFlag//// Desc: This function is called when the user selects the log out menu option.//// It switches all of the necessary variables back to the logged out settings.//////////////////////////////////////////////////////////////////////////////////////void LogOut(bool *pRunFlag){ int converted; converted = (int) LocalUserID; OnlineUserArray[(converted-65)] = 1; LocalUserID = ' '; PacketToSend = false; LocalUserLoggedIn = false; SendLoggedInMessage = true; SendLogInAcknowledgement = false; KeyBoardStateTracker = KEYLOGGEDOUT;}////////////////////////////////////////////////////////////////////////////////////////// Name: menuLoggedOut()//// Params: NONE//// Desc: This function displays the GUI for when the user is logged out.//////////////////////////////////////////////////////////////////////////////////////void menuLoggedOut(){ system("cls"); printf("\t=======================================\n"); printf("\t====== Not Logged In ======\n"); printf("\t=======================================\n"); printf("\t=======================================\n"); printf("\t 1. Log In\n"); printf("\n"); printf("\t 2. Exit\n"); printf("\n"); printf("\n"); printf("\t Enter Choice: ");}////////////////////////////////////////////////////////////////////////////////////////// Name: menuLoggedIn()//// Params: NONE//// Desc: This function displays the GUI for when the user is logged in. The if//// statements ensure that the correct current setting is shown for the //// toggleable options.//////////////////////////////////////////////////////////////////////////////////////void menuLoggedIn(){ system("cls");/* printf("\nOnline Contacts: "); for ( int i = 0; i <26; i++) { printf("%c", OnlineUserArray); }*/ // below is the menu items mixed with the users logged in on the right printf("\t===========MESSAGE SCROLLER============\n"); DisplayBufferContents(); printf("======="); printf("\t=======================================\n"); printf("Online="); printf("\t====== Logged in as %c ======\n", LocalUserID); printf("Users:="); printf("\t=======================================\n"); //printf("\t=======================================\n"); printf("%c%c%c%c%c%c=", OnlineUserArray[0], OnlineUserArray[1], OnlineUserArray[2], OnlineUserArray[3], OnlineUserArray[4], OnlineUserArray[5]); printf("\t 1. Log Out\n"); printf("%c%c%c%c%c%c=", OnlineUserArray[6], OnlineUserArray[7], OnlineUserArray[8], OnlineUserArray[9], OnlineUserArray[10], OnlineUserArray[11]); printf("\t 2. SendMessage\n"); printf("%c%c%c%c%c%c=", OnlineUserArray[12], OnlineUserArray[13], OnlineUserArray[14], OnlineUserArray[15], OnlineUserArray[16], OnlineUserArray[17]); printf("\t 3. Display Full Packet Contents -"); if (DisplayFullPacketContents == true) { printf(" ON\n"); } else { printf(" OFF\n"); } printf("%c%c%c%c%c%c=", OnlineUserArray[18], OnlineUserArray[19], OnlineUserArray[20], OnlineUserArray[21], OnlineUserArray[22], OnlineUserArray[23]); printf("\t 4. Use Extended Messaging -"); if (ExtendedMessaging == true) { printf(" ON\n"); } else { printf(" OFF\n"); } printf("%c%c =", OnlineUserArray[24], OnlineUserArray[25]); printf("\t 5. Exit\n"); printf("======="); printf("\n"); printf("\t Enter Choice: ");}////////////////////////////////////////////////////////////////////////////////////////// Name: main()//// Params: NONE//// Desc: Called upon application start up by windows. Calls all initiation //// functions. It also contains the main loop using a state-based //// architecture.//////////////////////////////////////////////////////////////////////////////////////int main(){ int hr; char CharacterRead; bool RunFlag = 1; bool *pRunFlag = &RunFlag for (int i = 0; i < 16; i++) { MessageToSendArray = '-'; } for (i = 0; i < 26; i++) { OnlineUserArray = '_'; } // When the app starts no user will be logged in if ( ( hr = InitiatePort("COM2") ) == false ) { printf("Initialising The Port FAILED!\n"); } else { printf("Initialising The Port SUCCEEDED!\n"); } printf("Clearing Packet Arrays...\n"); if ( ( hr = ClearPacketArrays() )== 0 ) { printf("Clearing Packet Arrays FAILED!\n"); } else { printf("Clearing Packet Arrays SUCCEEDED!\n"); } // Draw menu menuLoggedOut(); // Initialise the message buffer so that it is clear InitialiseBuffer(); while(RunFlag) { //KEYBOARD switch (KeyBoardStateTracker) { case KEYLOGGEDOUT: //If not logged in locally just track network users and pass on packets { // Check of user logging in if ( kbhit() ) { // Allocate memory for user selection char CharacterRead; while ( ( CharacterRead = getchar() ) == '\n' ) { menuLoggedOut(); } if (CharacterRead == '1') { //printf("Log In Here: "); while ( ( CharacterRead = getchar() ) == '\n') { menuLoggedOut(); printf("\n\n\t Capital Letter ID --> "); } int converted; // convert to upper case value converted = (int) toupper(CharacterRead); if ( (converted >= 65) && (converted <= 90) ) { InitialiseBuffer(); // Declare that im logged on in my log table OnlineUserArray[(converted-65)] = toupper(CharacterRead); // Establish that im logged in LocalUserLoggedIn = true; // Set Local User ID to newly signed in user LocalUserID = toupper(CharacterRead); // Switch to log in routines KeyBoardStateTracker = KEYLOGGEDIN; // Display the logged in menu menuLoggedIn(); // clear the buffer ready for use // Dont send again SendLoggedInMessage = true; } else { printf("\n Invalid ID"); menuLoggedOut(); } } else if (CharacterRead == '2') { RunFlag = 0; } } break; } case KEYLOGGEDIN: { if ( kbhit() ) { MenuBeingUsed = true; // Allocate memory for user selection char CharacterRead; while ( ( CharacterRead = getchar() ) == '\n' ) { menuLoggedIn(); } if (CharacterRead == '1') { int ConvertedValue; // convert to ascii value ConvertedValue = (int) toupper(LocalUserID); // Declare that im logged on in my log table OnlineUserArray[(ConvertedValue-65)] = '_'; // Establish that im logged in // Switch to log out routines KeyBoardStateTracker = KEYLOGGEDOUT; // Tell the transmitter to send a logged out packet SendLoggedOutMessage = true; // Display the logged out menu menuLoggedOut(); // Clear the buffer ready for the next log in LocalUserLoggedIn = false; } else if (CharacterRead == '2') { int ItemInMessageArray = 0; printf("\n\n\t Recipient ID: "); while ( ( CharacterRead = getchar() ) == '\n' ) { menuLoggedIn(); printf("\n\n\t Recipient ID: "); } RecipientOfNextMsg = CharacterRead; RecipientOfNextMsg = toupper(RecipientOfNextMsg); int converted2 = (int) toupper(RecipientOfNextMsg); printf("\t 10 Char Message: "); for (ItemInMessageArray; ItemInMessageArray < 10; ItemInMessageArray++) { while ( ( CharacterRead = getchar() ) == '\n' ) { menuLoggedIn(); printf("\n\t Recipient ID: %c", RecipientOfNextMsg); printf("\n\t 10 Char Message: "); } MessageToSendArray[ItemInMessageArray] = CharacterRead; } if ( OnlineUserArray[(converted2-65)] != toupper(RecipientOfNextMsg) ) { printf("\t**ERROR**User Does Not Exist!"); SendDataMessage = false; } else { SendDataMessage = true; menuLoggedIn(); } } else if (CharacterRead == '3') { if (DisplayFullPacketContents == true) DisplayFullPacketContents = false; else DisplayFullPacketContents = true; menuLoggedIn(); } else if (CharacterRead == '4') { if (ExtendedMessaging == true) ExtendedMessaging = false; else ExtendedMessaging = true; menuLoggedIn(); } else if (CharacterRead == '5') { RunFlag = 0; int ConvertedValue; // convert to ascii value ConvertedValue = (int) toupper(LocalUserID); // Declare that im logged on in my log table OnlineUserArray[(ConvertedValue-65)] = 0; // Establish that im logged in LocalUserLoggedIn = false; // Switch to log out routines KeyBoardStateTracker = KEYLOGGEDOUT; // Tell the transmitter to send a logged out packet SendLoggedOutMessage = true; // Display the logged out menu menuLoggedOut(); } } MenuBeingUsed = false; } } switch (TransmitStateTracker) { case TRANSMITTING: { if (LocalUserLoggedIn == true) { if (SendLoggedInMessage == true) { // Pass the packet type of L to create a log in packet CompilePacketToSend('L'); // Transmitt the log in packet SendPacket(); SendLoggedInMessage = false; } else if (SendLogInAcknowledgement == true) { // Send Aknowledgement packet back to sender only if the // sender isnt myself DO THIS BIT LATER CompilePacketToSend('R'); SendPacket(); SendLogInAcknowledgement = false; } else if (SendMessageAcknowledgement == true) { CompilePacketToSend('Y'); SendPacket(); SendMessageAcknowledgement = false; } else if (SendDataMessage == true) { CompilePacketToSend('D'); SendPacket(); SendDataMessage = false; } else if (SendGenericPacket == true) { SendPacket(); SendGenericPacket = false; } } if (SendLoggedOutMessage == true) { CompilePacketToSend('X'); SendPacket(); SendLoggedOutMessage = false; } break; } case NOTTRANSMITTING: { } } switch (RecieveStateTracker) { case RECIEVING: { bool bResult; CharacterRead = ReadCom(); bResult = DealWithRecievedCharacter(CharacterRead, pRunFlag); if (bResult == true) { DisassemblePacket(); } break; } case NOTRECIEVING: { } } } return 0;}
PS rating boost methinks :P
regards
ace
Ok, I think my program is good, but I think the circuit is the problem. Probably, you used a normal serial cable.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement