|
What is wrong for you with this presented code?
Doesn't it work properly?
Does it work tooooo long?
Why should it be improved?
|
|
|
|
|
It works but it could work more efficiently
For example is Rayleigh quotient calculated properly
or maybe i could use better shift and how to do it
Maybe better stop condition ?
Did you have numerical methods ?
Have you remember topics from this
|
|
|
|
|
You can improve the code by using real variable names, not A, B C.....
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You are very wise did you know that ?
|
|
|
|
|
You asked.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Finding roots of a polynomial is an ill-conditioned problem. There are better ways of dealing with this problem than using matrices.
|
|
|
|
|
Hello Members,
I am working on project and need to communicate LPC 2132 microcontroller and PC. I have connected PC and microcontroller through RS232 & RJ 45 cables.I am doing this communication in visual studio with c#. I have some coommand which I need to write and get response from microcontroller.
For ex: I have hex command- 0x25 0x52 0x02 0x01 0xDE
Response command- 0x25 0x0C 0x01 UHD-4k 02.10.09 0xC
I have created userinterface and when I send any hex command, the I get same command in terminal. What should I do to get resonse command if I put that above command.
Please help me out coz I am working on this since many days.
Regards,
Sanjay Siwach
|
|
|
|
|
Without seeing what your code is doing, or how you are handling data, we really can't help you - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
So show us the relevant code fragments - not the whole project, just the important bits - and tell us what you have tried and why it didn't work over the last "many days".
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Message Closed
modified 15-Feb-22 16:49pm.
|
|
|
|
|
What part ofQuote: So show us the relevant code fragments - not the whole project, just the important bits did you have difficulty understanding?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
When I send byte array command to microcontroller, the I get repsonse from microcontroller whatever I put condition in btnSend_click line.I have protocol command for this microcontrller, so, I just want to understand that I have to write condition what I want response from microcontroller or microcontroller should give me response automatically as protocol.
For ex_ I put condition here-
private void btnSend_Click(object sender, EventArgs e)
{
string s = txtSend.Text;
switch (s)
{
case "25520201DE":
rtxtDataArea.Text = "250C01UHD-4K02.10.09C2";
break;
default:
rtxtDataArea.Text = "busy";
break;
}
}
Hope you understood my point. Thankyou for your prompt reply. Really mean to me!
|
|
|
|
|
That doesn't send anything anywhere, or receive anything from anywhere. TextBoxes display to the user and fetch user input, they have nothing to do with RS232.
And your receive data event handler overwrites the existing data each time it gets a character! You do realize that serial data arrives byte by byte and that you get a DataReceived event fired for each?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello,
Thankyou for your prompt reply. I feel sorry to reply late because of some problem.
Please read the following and let me know what will be procedure to do:-
Write “Key – KEY_WB” request
« %W 0x03 0x02 0xF3 LRC »
____________________________________________
Write “Key – KEY_WB” response
« % W 0x02 ACK LRC »
LRC = XOR complete message
STAT = ACK (0x06) = OK
NAK (0x15) = not OK
BUSY (0x07) = in process
In case of negative answer (NACK) the request must be repeated until a positive answer
(ACK) has been received. The delay time for a new request has a minimum of 100ms.
In case of answer (BUSY) the sender has to wait until the answer (ACK) has been
received.
In every case; each request must be answered with an response. The host has to wait on
an response.
|
|
|
|
|
Most probably your LPC2132 is configured in 'echo mode'. That means it does return every received character. This is a kind of simple 'handshake'.
|
|
|
|
|
Hello,
Let me explain the procedure so you can understand fully.I have system which includes microcontroller LPC 2132 and the system has 6 keypad Menu, so, I need to get these menu function to PC. Every key has specific command with which the microcontroller will respond some command. I connected the system(DB-9) and serial interface PC(RJ45) and uploaded firmware through flash magic software. After uploading this, I need to write a programm having some commands according to key button on the keypad of the system. I have created GUI with all essential requirement like baud rate, parity, stop, hex command, connect and send data.
Note<:- When I connect the system and PC through user interface, automatically it show command continuously in terminal which i created on GUI that command which are following
Read = 0x90 & Read = 0x9F
Then I send some hex command in send command then it does not show anything, so, i need to press 'Standbykey' button on the system then I get same command in terminal which is following:-
private byte[] HexStringToByteArray(string s)
{
s = s.Replace(" ", "");
byte[] buffer = new byte[s.Length / 2];
for (int i = 0; i < s.Length; i += 2)
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
return buffer;
}
private void btnSend_Click(object sender, EventArgs e)
{
sendData();
}
But, if I change the structure with some command in btnSend_Click(object sender, EventArgs e) then
private void btnSend_Click(object sender, EventArgs e)
{
case "25520201DE":
rtxtDataArea.Text = "25520C01UHD-4K02.10.09C2"
break;
default:
rtxtDataArea.Text = "busy"
}
I get waht I want in terminal(richtextbox). This is the result.
Please let me know any other programm i need to write or change anything. Thank you for your support.Hope you understood my point.
}
|
|
|
|
|
When a peripheral seems to return whatever you send to it, that usually means your cabling is faulty, e.g. you forgot to connect the voltage reference ("ground"), or you switched data in and data out wires.
Suggestion: get your hardware in working order before investing in software.
Things that may help:
1. write a simple (I repeat: simple) program that just sends a command periodically, at best something your peripheral should react on with some visual feedback (e.g. blinking a LED).
Best: add some LEDs to your peripheral and implement one-byte commands to turn them on/off.
("observability is the key to success")
2. alternatively: do whatever it takes to make your peripheral send known data, and capture that with a (virtual) terminal.
3. do make sure your serial port parameters (baud rate, parity, stop bits,...) are identical on both sides.
As long as neither 1 or 2 works, your hardware connection is not good.
PS: NEVER write software that swallows exceptions; they exist to tell you what goes wrong where; ignoring them (or reducing them to error=true) is a criminal offence.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
Luc Pattyn wrote: NEVER write software that swallows exceptions; So true.
I inherited a project that had this, after a good amount of time trying to trace down a problem, I eventually stumbled upon an empty catch block, rage could not adequately describe what I felt.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
modified 12-Jan-22 13:42pm.
|
|
|
|
|
I connected serial interface PC(RJ-45) and sytsem includes LPC2132 (DB-9) and uploaded firmware through flash magic software with setting of same baud rate, parity, stop bits . Then I created GUI with terminal in visual studio with c#.Net and wrote programm accordingly.Please check the following:-
//Convert a string of hex digits (example: E1 FF 1B) to a byte array.
//The string containing the hex digits (with or without spaces)
//Returns an array of bytes.
private byte[] HexStringToByteArray(string s)
{
s = s.Replace(" ", "");
byte[] buffer = new byte[s.Length / 2];
for (int i = 0; i < s.Length; i += 2)
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
return buffer;
}
private void btnSend_Click(object sender, EventArgs e)
{
sendData();
}
In this way when I send commands "0x25 0x52 0x02 0x01 0xDE" , I get the same in virtual termanl.
When I put the command in btnSend_click(object sender, EventArgs e)
like
private void btnSend_Click(object sender, EventArgs e)
{
case "25520201DE":
rtxtDataArea.Text = "25520C01UHD-4k02.10.09C2";
break;
default:
rtxtDataArea = "busy";
break;
}
I get the result what I wrote in rtxtDataArea.Text.
Note:- The cable is not purchased from anywhere but prepared for this specific purpose.I think cable is not faulty.
If you can check my command things, are these are correct if not please let me know is any other way to do it. Thankyou for your support.
|
|
|
|
|
Hi,
1. your HexStringToByteArray() method seems OK as long as the input string is just hex and spaces. It does not contain error handling.
2. A wild guess: add the following to your port initialization:
ComPort.Handshake=Handshake.None;
ComPort.Encoding=Encoding.GetEncoding(28591);
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
Hello,
I tried this command as suggested but not working. Can you elaborate on the following :-
Request „Read" :
« %R NUM CMD LRC »
Response „Read":
« %R NUM CMD DATA LRC »
__________________________________________________________________________
Request „Write":
« %W NUM CMD Data LRC »
Response „Write":
« %W NUM STAT LRC »
% = Start of message
R/W = Read/Write
CMD = Command
NUM = length of message (all bytes excluding „% R/W NUM")
DATA = real data
LRC = XOR complete message
STAT = ACK (0x06) = OK
NAK (0x15) = not OK
BUSY (0x07) = in process
In case of negative answer (NACK) the request must be repeated until a positive answer
(ACK) has been received. The delay time for a new request has a minimum of 100ms.
In case of answer (BUSY) the sender has to wait until the answer (ACK) has been
received.
In every case; each request must be answered with an response. The host has to wait on
an response.
|
|
|
|
|
OK, it looks like your setup is using binary data and a simple protocol with some checksum. I've done lots of those in the past. Most of the time, the problem is with the checksum. In order to help you, I need as much information as possible, such as:
1. what is the function of your peripheral? what kind of device is it? does it have its own user interface? any display? any LEDs?
2. what is the status of your peripheral? is it an existing commercial product? who is manufacturing it? what would be its ordering code? does it show on any website? or is it (a prototype of) your own development? or someone else's ongoing development?
3. is the programming or communication with it documented? is such document publicly available? can you provide a link to it? if not, can you copy:
- the list of supported commands;
- several published examples of commands/responses;
- detailed explanation on the checksum.
4. are you capable of sending it some command that actually causes something to happen at the peripheral side? e.g. power down? beep? blink a LED? ...
5. are you capable of sending it some command that actually results in something being sent back to your PC? if so, please provide several examples of what you send and what you receive (in all hex please).
6. in your original post you mentioned the command 0x25 0x52 0x02 0x01 0xDE
if 0xDE is to be the LRC, I can't imagina what checksum algorithm is being used (sum or XOR would yield very different values)
7. In your latest message here you mentioned
Request „Read" : « %R NUM CMD LRC »
Request „Write": « %W NUM CMD Data LRC »
It is not clear:
- whether CMD is always one byte, or could be many bytes.
- whether NUM should or should not include LRC
- how exactly LRC should be calculated
8. You wrote
rtxtDataArea.Text = "250CUHD-4K02.10.09C22";
Where did that string come from? did you actually receive that? or was it in some document? or what?
it does not easily fit the pattern « %R NUM CMD DATA LRC »
yes 0x25 is %
and 0x0C (12.) would be NUM, the length
but CMD seems missing
and to match length 12. the data probably was: U H D - 4 K 0x02 . 0x10 . 0x09 C
and finally LRC = 0x22
or do you see another way of matching this up to the pattern?
9. in one of your posts you mentioned
Read = 0x90 & Read = 0x9F
which is a complete mystery to me
Please provide ample, accurate, reliable answers as much as you can to each of my numbered paragraphs if you want this solved any time soon...
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
 Hello Luc Pattyn,
First of all, thank you very much for your attention on this topic.
Iwill try to give you information as much as I can which is following:-
1. This is not publicaly available anywhere as i found and researched about it. I am working on a project as my thesis topic.
In this one, I have a manufactured system which is having 6 keys on main keypad which is controllable by some other 4 keys. Now I need to get control of 6 keys through serial interface PC. To get this, i need to communicate the system to PC. The company gave me protocol and in this protocol mentioned that I need to connect the system and PC through serial communication and every key has command which I need to send these commands to the system which includes microcontroller LPC2132.
I mention 1 example here which is mentioned in protocol and need to follow the procedure:-
1.
Write "Key – KEY_WB" request
« %W 0x03 0x02 0xF3 LRC »
____________________________________________
Write "Key – KEY_WB" response
%W 0x02 ACK LRC
Remaining keys command I need to prepare on my own according to this.
% = Start of message
R/W = Read/Write
CMD = Command
NUM = length of message (all bytes excluding „% R/W NUM")
DATA = real data
LRC = XOR complete message
STAT = ACK (0x06) = OK
NAK (0x15) = not OK
BUSY (0x07) = in process
In case of negative answer (NACK) the request must be repeated until a positive answer
(ACK) has been received. The delay time for a new request has a minimum of 100ms.
In case of answer (BUSY) the sender has to wait until the answer (ACK) has been
received.
In every case; each request must be answered with an response. The host has to wait on
an response.
Yes, I have commands for LED as well but first I want to write the commands for above key then I think remaining work can be done.
As per protocol, I have connected both system and serial interface PC through DB9- RJ45 cable which also prepared by manufacturer of system. After this, I have uploaded firmware version through Flashmagic software tool. Now I created GUI for implementing these commands but is not working as I expect becuase of some lacking in knowledge about these specific ack response commands. Now I would like to know about the command in which I can get response with ack byte from microcontroller side.
I think I tried to give you enough information to understand the project. If still need, I can give more information. Please advise me on this for further progress.
Thanks & regards,
|
|
|
|
|
You are repeating yourself rather than providing the information I asked for; yousimply ignoredmost of my questions. I will not repeat them.
Please go back to my previous message and try to answer points 4, 5 and 6 to begin with.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|
Hello Luc pattyn,
I apologize for this mistake. The system is not opened and can not see if any LED is blinking.
Ans 5 when I send commands , I get exactly same command in receiving terminal.
Ans 6 For LRC, 0xDE is given in the protocol.
Regards,
Sanjay
|
|
|
|
|
I assume "LRC" is some kind of checksum. A checksum is meant to protect devices against damaged commands, so what they do is calculate the correct checksum, compare with the received checksum. If identical, execute command; if different, ignore command (and maybe send something indicating that). So as long as your checksums are not correct, nothing much is going to work.
Sanjay Siwach wrote: 0xDE is given in the protocol.
Huh? Can you point to or show the document that describes "the protocol".
I can only hope it is more detailed and more accurate than what you have provided so far.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.
|
|
|
|
|