Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/09/08 12:13
Read: times


 
Msg Score: -1
 -1 Off-Topic
#153047 - C++, 8051, cleaning up a mess......need advise
I have a piece software that communicates to my 8051 via an I2C bus byte by byte. This software has 3 to 4 byte sends depending on what it is talking to. It uses edit boxes to input the data from the user manually (debugging etc). The edit box is set up as a string input and then converted to a short or byte.....(in which warnings are given during compile.

If the edit box is empty, it prepopulates with the string "0x" and then as you type should end up as 0x01, 0x23.....00-FF range.

The mess and problem I'm having is all of that works BUT only for the FIRST of the TWO numbers/letters entered.....

If I were to type 2 5 on the keyboard, the edit box is supposed to end up as 0x25, but instead it starts as 0x2 and when you go to press the 5, the edit box puts the cursor as the BEGINNING of the string and when you press the 5 it becomes 0x05.

Now if I do the above again, but instead of hitting the 5 and use the mouse to put the cursor at the end of the string, and then type 5, I end up with 0x25 and went send the system responds as it should.

I would like to correct this because I HAVE to use this software every day (relatively new to the company) and its a real pain to do this dog and pony show to get the bytes to be sent to my micro.

I'm not a C++ expert and would rate and low end intermediate (knows the way around, and modify) but not enough to effectively understand this problem.

Here is the code for 1 of the boxes.....they are all the same......I've put what I thought would be the solution, but I get assertion errors when I run it......can someone guide me as to what I need to do? I can find any option that allows the cursor to be sent to "end of line" after the get input stream.


Original code
UpdateData(TRUE);			// get data from the GUI
	if(m_strRegAddr.Find("0x") == -1) m_strRegAddr = "0x" + m_strRegAddr;
	byte byValue = ((DWORD)strtoul(m_strRegAddr, NULL, 16) <256)? (DWORD)strtoul(m_strRegAddr, NULL, 16) :255;
								//	strtoul converst a string into an unsigned-long-integer -- string which must be converted, 
								//  If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr,
								//	it stops reading in till it finds a value larger than expressed, this case 16.
	byValue = (byValue >0) ? byValue :0;		// ? is kind of if statement if (...) is true than x : else y
	m_strRegAddr.Format("0x%x",byValue);	// herewith you put it back in edit box with 0x and than the hex value
	UpdateData(FALSE);
	device = byValue;
	 




What I tried
UpdateData(TRUE);			// get data from the GUI
	if(m_strDeviceAddress.Find("0x") == -1) m_strDeviceAddress = "0x" + m_strDeviceAddress;
	byte byValue1 = ((DWORD)strtoul(m_strDeviceAddress, NULL, 16) <256)? (DWORD)strtoul(m_strDeviceAddress, NULL, 16) :255;
								//	strtoul converst a string into an unsigned-long-integer -- string which must be converted, 
								//  If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr,
								// it stops reading in till it finds a value larger than expressed, this case 16.
	byValue1 = (byValue1 >0) ? byValue1 :0;		// ? is kind of if statement if (...) is true than x : else y
    
	
	UpdateData(TRUE);			// get data from the GUI
	byte byValue2 = ((DWORD)strtoul(m_strDeviceAddress, NULL, 16) <256)? (DWORD)strtoul(m_strDeviceAddress, NULL, 16) :255;
								//	strtoul converst a string into an unsigned-long-integer -- string which must be converted, 
								//  If endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr,
								// it stops reading in till it finds a value larger than expressed, this case 16.
	byValue2 = (byValue2 >0) ? byValue2 :0;		// ? is kind of if statement if (...) is true than x : else y
    

	m_strDeviceAddress.Format("0x%x%y",byValue1, byValue2);	// herewith you put it back in edit box with 0x and than the hex value
	UpdateData(FALSE);
	device = (byValue1, byValue2);



The data must proper in one of all four edit boxes and a "send" button is used to parse all four edit boxes and so forth, that is why the UpdateData(false) is present. The UpdateData(TRUE) is to capture the input stream and populate the edit box, then when completed, if all four have the correct formatted data, the send command sends the byte stream over teh I2C bus.

List of 18 messages in thread
TopicAuthorDate
C++, 8051, cleaning up a mess......need advise            01/01/70 00:00      
   Trying to convert after typing is too hard            01/01/70 00:00      
   Take a look here...            01/01/70 00:00      
      I gave that a run,            01/01/70 00:00      
   Maybe this will help            01/01/70 00:00      
      Thanks Russ, some thoughts            01/01/70 00:00      
         More thoughts            01/01/70 00:00      
            Your right, you know how it is            01/01/70 00:00      
      Is this it?            01/01/70 00:00      
         Well, no            01/01/70 00:00      
            Hopefully I can answer this correctly            01/01/70 00:00      
               Is Prosise onlin?            01/01/70 00:00      
                  Emailed link to you            01/01/70 00:00      
               Two more questions            01/01/70 00:00      
                  Placeholders for array data            01/01/70 00:00      
               Stop now, before you make things worse!            01/01/70 00:00      
                  No offense taken at all            01/01/70 00:00      
                     I got the link            01/01/70 00:00      

Back to Subject List