15,898,931 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 11961673 (Top 21 by date)
Member 11961673
19-Sep-15 11:38am
View
what is regex? i m not aware of this . i want the code for the above mentioned problem since am very new to c#
Member 11961673
19-Sep-15 11:37am
View
no.i just want to fetch the file name from the entire string and update my GUI with the message
Member 11961673
5-Sep-15 12:51pm
View
sorry i m very new to all this. i will remove it
Member 11961673
5-Sep-15 12:31pm
View
all the above are the functions of one of the class of the single project. the other class has some functions that uses the concept of threads. if required i wil post the other class's functions also.
plz help me out in solving this hanging issue.
Member 11961673
5-Sep-15 12:27pm
View
Deleted
private bool CheckAsyncMsgRxvd(CanMessage SucessCANMessage)
{
bool status = false;
//bool MsgRead = false;
////Initializes a new instance CommTimer class
CommTimer AsyncMsgRxvdCommTimer = new CommTimer();
////start the timmer for 1 sec
AsyncMsgRxvdCommTimer.Start(Properties.Settings.Default.timeOutInterval);
//// wait until any message is recieved and timeout status is false
while ((this._AsyncMsgRxvdQueue.Count <= 0) && (AsyncMsgRxvdCommTimer.Timedoutstatus == false) && (_CancelStatus == false))
{
}
// AsyncMsgRxvdCommTimer.Dispose();
// if (this._AsyncMsgRxvdQueue.Count == 1 )
//while(this._AsyncMsgRxvdQueue.Count > 0 && (AsyncMsgRxvdCommTimer.Timedoutstatus == false) )
while (AsyncMsgRxvdCommTimer.Timedoutstatus == false && _CancelStatus == false)
{
//read the CAN Message present in the Queue one by one
if (_AsyncMsgRxvdQueue.Count > 0)
{
_AsyncMsgRxvd = this._AsyncMsgRxvdQueue.Dequeue();
}
// MsgRead = true;
//if (status)
//{
//returns true if CAN Message recieved is same as Success CAN Message
if ((_AsyncMsgRxvd.Data == SucessCANMessage.Data) && (_AsyncMsgRxvd.Id == SucessCANMessage.Id) && (_AsyncMsgRxvd.Length == SucessCANMessage.Length))
{
status = true;
AsyncMsgRxvdCommTimer.Dispose();
break;
}
else
{
//thread.sleep(100);
}
//}
}
// return MsgRead;
//function call to read the CAN Message present in the AsyncMsgRxvdQueue
//returns true if there is some message is present in the AsyncMsgRxvdQueue to read
//status = ReadAsyncMsg();
return status;
}
Member 11961673
5-Sep-15 12:27pm
View
Deleted
private bool ReadAckMsg()
{
bool DataRead = false;
////Initializes a new instance CommTimer class
CommTimer objCommTimer = new CommTimer();
////start the timmer for 1 sec
objCommTimer.Start(Properties.Settings.Default.timeOutInterval);
//// wait until any message is recieved and timeout status is false
while ((this._AckNackRspQueue.Count <= 0) && (objCommTimer.Timedoutstatus == false))
{
}
objCommTimer.Dispose();
if (this._AckNackRspQueue.Count == 1)
{
// Read the acknowledgement form the AckNackRspQueue
AckNackRsp = this._AckNackRspQueue.Dequeue();
DataRead = true;
}
return DataRead;
}
Member 11961673
5-Sep-15 12:26pm
View
Deleted
private bool SendCommand(string strCANCommand, CanMessage SuccessCANMessage)
{
// this._recievedMsg = string.Empty;
bool status = false;
AckNackRsp = '\0';
int ackItr = 0;
bool statusAckNackRsp = false;
bool statusAsyncMsgRxvd = false;
int MsgRxvdItr = 0;
//// call the WriteData Method again for maximum 3 times if statusAckNackRsp is true and statusAsyncMsgRxvd is true
do
{
// this._recievedMsg = string.Empty;
this._AckNackRspQueue.Clear();
this._AsyncMsgRxvdQueue.Clear();
// Clear the CANUSB converter buffer before sending the CAN Command
status = ClearUSBCANBuffer();
//if CAN Buffer is Cleared Successfully
if (status)
{
//function call to send CAN Command to the serial port
this.WriteData(strCANCommand);
// function call to check the response of the Command returns true is correct acknowledgement is recieved
statusAckNackRsp = CheckAckNackRsp();
// if correct acknowledgement is recieved
if (statusAckNackRsp == true)
{
//Function Call to read and Check the Response from the target device returns true if response CAN Message is same as Success CAN Message
statusAsyncMsgRxvd = CheckAsyncMsgRxvd(SuccessCANMessage);
// if response CAN Message is not same as Success CAN Message increment the CAN Message recieved iterator
if (statusAsyncMsgRxvd == false)
{
MsgRxvdItr++;
}
}
// if wrong acknowledgement is recieved increment the acknowledgement iterator
else
{
ackItr++;
}
}
} while ((!statusAckNackRsp || !statusAsyncMsgRxvd) && (ackItr < 3) && (MsgRxvdItr < 3) && (_CancelStatus == false));
if ((statusAckNackRsp && statusAsyncMsgRxvd))
{
status = true;
}
else
{
status = false;
}
return status;
}
Member 11961673
5-Sep-15 12:25pm
View
Deleted
if (_Lineaddress > _CurrentMemoryAddress)
{
UInt32 addressdifference = _Lineaddress - _CurrentMemoryAddress;
for (uint i = 0; i < addressdifference; i++)
{
string str = "FF";
_List.Add(str);
_CurrentMemoryAddress++;
}
status = true;
}
if (_Lineaddress == _CurrentMemoryAddress)
{
for (int i = 0; i < Convert.ToInt16(a[0]); i++)
{
int x = (Convert.ToInt16(a[4 + i]));
string str = string.Empty;
if ((x <= 15) && (x >= 0))
{
str = "0" + x.ToString("X");
}
else
{
str = x.ToString("X");
}
_List.Add(str);
_CurrentMemoryAddress++;
}
status = true;
}
else if (_Lineaddress < _CurrentMemoryAddress)
{
for (int i = 0; i < Convert.ToInt16(a[0]); i++)
{
int Position = 0;
Position = (int)(_Lineaddress - Convert.ToUInt32(_Startingaddress, 16));
if (Position > 0 && Position < _List.Count)
{
int x = (Convert.ToInt16(a[4 + i]));
string str = string.Empty;
if ((x <= 15) && (x >= 0))
{
str = "0" + x.ToString("X");
}
else
{
str = x.ToString("X");
}
_List[Position] = (str);
_Lineaddress++;
}
}
status = true;
}
return status;
}
Member 11961673
5-Sep-15 12:25pm
View
/// Extendeds the type of the address record.
///
/// <param name="Lineaddress">The lineaddress.</param>
/// <param name="a">a.</param>
private bool ExtractandStroreDataBytes(UInt32 Lineaddress, char[] a)
{
bool status = false;
UInt32 _Lineaddress = Convert.ToUInt32(_Jumptoaddress, 16) + Lineaddress;
if ( _selectController == 1 && _Lineaddress < 4294705152)
{
return true;
}
else if (_selectController == 2 && _Lineaddress < 65536)
{
return true;
}
if (_Lineaddress < Convert.ToUInt32(_Startingaddress, 16))
{
return false;
}
if (_Lineaddress >= 4294967200 && _Lineaddress <= 4294967295)
{
return true;
}
Member 11961673
5-Sep-15 12:23pm
View
Deleted
////End of file record
default:
case (char)1:
////End of the hex file
stat_unAddressToWrite = 0;
parsedHexData = string.Empty;
break;
////Extended segment address
case (char)2:
////Address considered as the offset with the normal address
stat_unAddressToWrite = 0;
parsedHexData = string.Empty;
break;
////Start segment address
case (char)3:
parsedHexData = string.Empty;
break;
////Extended linear address
case (char)4:
// parsedHexData = string.Empty;
// stat_unAddressToWrite = 0;
//uint x = Convert.ToUInt16(stat_pucTempBuff[4]);
//uint y = Convert.ToUInt16(stat_pucTempBuff[5]);
_Jumptoaddress = Convert.ToUInt16(stat_pucTempBuff[4]).ToString("X") + Convert.ToUInt16(stat_pucTempBuff[5]).ToString("X") + "0000";
// string m = jumptoaddress + multiplicationfactor;
// uint p = Convert.ToUInt16(m);
uint p = Convert.ToUInt32(_Jumptoaddress, 16);
// z = Convert.ToUInt16(x * y);
// Lineaddress = p * multiplicationfactor;
//AddDefaultValueatMissingAddress(p);
//////////if (((x + y) > 506) && ((x + y) < 511))
//////////{
////////// jumpaddress = (65535 * (x + y - 507));
//////////}
parsedHexData = string.Empty;
break;
////Start linear address
case (char)5:
////This has the physical address of the controller from where the code execution has to start
parsedHexData = string.Empty;
stat_unAddressToWrite = 0;
break;
}
return parsedHexData;
}
Member 11961673
5-Sep-15 12:22pm
View
Deleted
////Record type
switch (stat_pucTempBuff[3])
{
//// Data record
case (char)0:
////Record type is normal
//stat_unAddressToWrite = unAddressInHexFile;
//parsedHexData = strDataRecord.Substring(9, length * 2);
int a = (Convert.ToInt16(stat_pucTempBuff[1])) * 256;
int b = Convert.ToInt16(stat_pucTempBuff[2]);
int address = (a + b);
if (_List.Count == 0)
{
_Startingaddress = (Convert.ToUInt32(_Jumptoaddress, 16) + address).ToString("X");
_CurrentMemoryAddress = Convert.ToUInt32(_Startingaddress, 16);
}
bool status = ExtractandStroreDataBytes(Convert.ToUInt32(address), stat_pucTempBuff);
if (status)
{
parsedHexData = string.Empty;
}
else
{
return null;
}
break;
Member 11961673
5-Sep-15 12:22pm
View
Deleted
//// Address error...
if (stat_unAddressToWrite > unAddressInHexFile)
{
if (stat_pucTempBuff[3] == 0)
{
//// ...return the frame error
return null;
}
}
//Check for the starting of the application code, remove the duplicated data from 0x0000 to 0x0030
// This is the starting address of the application of the Siderail motor control controller
//if(currentMemoryAddress
//if ((unAddressInHexFile < 0x100) && (stat_pucTempBuff[3] == 0))
//{
// return string.Empty;
//}
//// If the record type if invalid
if ((stat_pucTempBuff[3] < 0) || (stat_pucTempBuff[3] > 5))
{
//// ...If record type is invalid, return error
return null;
}
//// Get the Checksum value
char checksum =
(char)Convert.ToInt16(Convert.ToInt16(strDataRecord.Substring(9 + stat_pucTempBuff[0] * 2, 2), 16));
//// Compare that with the calculated checksum value...
if (this.CalculateCheckSum((char[])stat_pucTempBuff, stat_pucTempBuff[0] + 4) != checksum)
{
//// ...If they are not same, return error
return null;
}
Member 11961673
5-Sep-15 12:22pm
View
Deleted
Get the Data bytes present in the data record of Intel Hex file
///
/// <param name="strDataRecord">Single Data record of Intel Hex file</param>
/// <returns>Data bytes if present
public string ParseHex(string strDataRecord)
{
try
{
uint stat_unAddressToWrite = 0;
string parsedHexData = null;
int dlc = 0;
int parameterSize = strDataRecord.Length;
char[] pucData = strDataRecord.ToCharArray();
//Length of the character array is calculated
char[] stat_pucTempBuff = new char[(parameterSize - 1) / 2];
int unIndex = 2;
uint unIndexTemp = 1;
////Data format for intel hex
if (pucData[0] != ':')
{
return null;
}
////calculate number of data bytes present
dlc = Convert.ToInt16(Convert.ToInt32(strDataRecord.Substring(1, 2), 16));
////Confirmance of the length
if (parameterSize != (dlc * 2 + 11))
{
return null;
}
unIndex = 2;
unIndexTemp = 1;
stat_pucTempBuff[0] = (char)dlc;
//// Decode the string value into meaningful hex values
//// Example 0x2F will be received from host as '2' 'F'
//// So we will need to convert '2' 'F' to 0x2F
while (unIndex < (stat_pucTempBuff[0] * 2 + 8))
{
stat_pucTempBuff[unIndexTemp++] = (char)Convert.ToInt16(Convert.ToInt16(strDataRecord.Substring(1 + unIndex, 2), 16));
unIndex += 2;
}
//// Validation of the address
uint unAddressInHexFile = stat_pucTempBuff[1];
unAddressInHexFile <<= 8;
unAddressInHexFile |= stat_pucTempBuff[2];
Member 11961673
5-Sep-15 12:21pm
View
Deleted
public bool VerifyHexfile(string strFiletoSend)
{
try
{
string line;
_List.Clear();
_Jumptoaddress = "0000";
_CurrentMemoryAddress = 0;
////Initialize the new Stream Reader object to read the file content
StreamReader fileStream = new StreamReader(strFiletoSend);
// AssignStartingAddress();
string payload = null;
////read the content of file line by line
while ((line = fileStream.ReadLine()) != null)
{
////function call to get the data bytes in the line
payload = this.ParseHex(line);
//// if Correpted Hex file payload is null so return false otherwise return true
if (null == payload)
{
////dispose the steram reader object
fileStream.Dispose();
//// return false as selected Hex file is Corrupted
return false;
}
}
////dispose the stream reader object
fileStream.Dispose();
////return true as selected Hex file is OK
return true;
}
catch (Exception ex)
{
throw ex;
}
}
Member 11961673
5-Sep-15 12:19pm
View
Deleted
case STATE.RESPONSE:
// Append the received char
if ((Char.IsLetterOrDigit(ch)) || (ch == '*'))
{
// The message body
rawmsg.Append(ch);
}
else
{
state = STATE.FIRST;
// Not a hex value
if (ch == '\r')
{
// We have reached the end of the message
isCanMessage = STATE.RESPONSE;
retval = rawmsg.ToString();
}
else if (ch == '\a')
{
throw new Exception("Unexpected NACK Rxved during reception of Response" + ch.ToString());
}
else
{
// We have received an invalid char Exit
throw new Exception("Invalid char Rxved during reception of Response" + ch.ToString());
}
}
break;
}
return (retval);
}
catch (Exception exception)
{
throw exception;
}
}
Member 11961673
5-Sep-15 12:18pm
View
Deleted
case STATE.CANMSG:
// Append the received char
if (((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'F')))
{
// The message body
rawmsg.Append(ch);
}
else
{
state = STATE.FIRST;
// Not a hex value
if (ch == '\r')
{
// We have reached the end of the message
isCanMessage = STATE.CANMSG;
retval = rawmsg.ToString();
}
else if (ch == '\a')
{
throw new Exception("Unexpected NACK Rxved during reception of CAN Message" + ch.ToString());
}
else
{
// We have received an invalid char Exit
throw new Exception("Invalid char Rxved during reception of CAN Message" + ch.ToString());
}
}
break;
Member 11961673
5-Sep-15 12:12pm
View
Deleted
private string ParseChar(char ch, out STATE isCanMessage)
{
try
{
string retval = "";
isCanMessage = STATE.EMPTY;
// Process char
switch (state)
{
case STATE.FIRST:
if (ch == '\r')
{
isCanMessage = STATE.RESPONSE;
retval = "\r";
}
// If there is an \a, this is taken to be a NACK
else if (ch == '\a')
{
isCanMessage = STATE.RESPONSE;
retval = "\a";
}
// Check for a CAN message received
else if ((ch == 't') || (ch == 'T') ||
(ch == 'r') || (ch == 'R'))
{
// Clear the string and add the byte..
rawmsg.Length = 0; // Clear string builder contents
rawmsg.Append(ch);
// Get the rest of the message
state = STATE.CANMSG;
}
// Check for a response to see if it a response to a messages that may have been sent
else if ((ch == 'F') || (ch == 'V') || (ch == 'N') ||
(ch == 'z') || (ch == 'Z'))
{
// Clear the string and add the byte..
rawmsg.Length = 0; // Clear string builder contents
rawmsg.Append(ch);
// Get the rest of the message
state = STATE.RESPONSE;
}
else
{
state = STATE.FIRST;
// Unrecognised char. Idle.
throw new Exception("ClassAckNackRspRxvdParser Error=" + ch.ToString());
}
break;
case STATE.CANMSG:
// Append the received char
if (((ch >= '0') && (ch <= '9')) || ((ch >= 'A') && (ch <= 'F')))
{
// The message body
rawmsg.Append(ch);
}
else
{
state = STATE.FIRST;
// Not a hex value
if (ch == '\r')
{
// We have reached the end of the message
isCanMessage = STATE.CANMSG;
retval = rawmsg.ToString();
}
else if (ch == '\a')
{
throw new Exception("Unexpected NACK Rxved during reception of CAN Message" + ch.ToString());
}
else
{
// We have received an invalid char Exit
throw new Exception("Invalid char Rxved during reception of CAN Message" + ch.ToString());
}
}
break;
case STATE.RESPONSE:
// Append the received char
if ((Char.IsLetterOrDigit(ch)) || (ch == '*'))
{
// The message body
rawmsg.Append(ch);
}
else
{
state = STATE.FIRST;
Member 11961673
5-Sep-15 12:11pm
View
Deleted
private string ParseChar(char ch, out STATE isCanMessage)
{
try
{
string retval = "";
isCanMessage = STATE.EMPTY;
// Process char
switch (state)
{
case STATE.FIRST:
if (ch == '\r')
{
isCanMessage = STATE.RESPONSE;
retval = "\r";
}
// If there is an \a, this is taken to be a NACK
else if (ch == '\a')
{
isCanMessage = STATE.RESPONSE;
retval = "\a";
}
// Check for a CAN message received
else if ((ch == 't') || (ch == 'T') ||
(ch == 'r') || (ch == 'R'))
{
// Clear the string and add the byte..
rawmsg.Length = 0; // Clear string builder contents
rawmsg.Append(ch);
// Get the rest of the message
state = STATE.CANMSG;
}
// Check for a response to see if it a response to a messages that may have been sent
else if ((ch == 'F') || (ch == 'V') || (ch == 'N') ||
(ch == 'z') || (ch == 'Z'))
{
// Clear the string and add the byte..
rawmsg.Length = 0; // Clear string builder contents
rawmsg.Append(ch);
// Get the rest of the message
state = STATE.RESPONSE;
}
else
{
state = STATE.FIRST;
// Unrecognised char. Idle.
throw new Exception("ClassAckNackRspRxvdParser Error=" + ch.ToString());
}
break;
Member 11961673
5-Sep-15 12:10pm
View
Deleted
This method will be called when there is data waiting in the buffer
void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
///Read the data
StringBuilder builder = new StringBuilder();
while (this._comPort.BytesToRead > 0)
{
builder.Append(this._comPort.ReadExisting());
}
if (builder.Length > 0)
{
this._recievedMsg = builder.ToString();
}
ReadData(_recievedMsg);
}
catch (Exception exception)
{
throw exception;
}
}
Member 11961673
5-Sep-15 12:08pm
View
Deleted
this function writes data to the serial communication port,waits for response for max 1 Sec, stores the response in "_recievedMsg" member variable
private void WriteData(string strMsg)
{
try
{
////first make sure the port is open
////if its not open then open it
if (this._comPort.IsOpen == false)
{
this._comPort.Open();
}
// discard data present in input and output buffer of serial communication port
this._comPort.DiscardInBuffer();
this._comPort.DiscardOutBuffer();
this._comPort.WriteTimeout = 10000;
////send the message to the port
this._comPort.Write(strMsg);
}
catch (Exception exception)
{
throw exception;
}
}
Member 11961673
5-Sep-15 12:03pm
View
Code dump removed...
Show More