|
Provide the code snippet of Client that make connect request and code snippet that listens on a port xyz. With that people can help you.
|
|
|
|
|
I have 4 CAsyncSocket derived classes wrapped inside 4 Derived CWinThread Class
in the CWinThread::Initinstance I set the ipaddr = "192.168.1.4"
When I use NULL as the last parameter in the CAsynSocket::create or BIND I am successful in creating
a socket however when I use the ipaddr "192.168.1.4" the ipaddr of the machine I get
WSAEADDRNOTAVAIL
The listening code is MainFrame Assembler EZASMI select which is intended to process multiple I/O's
on multiple sockets
EZASMI TYPE=SELECT, Issue Macro
MAXSOC=MAXSOC1, SPECIFY MAXIMUM NUMBER OF SOCKETS
TIMEOUT=TIMEVAL,
RSNDMSK=RSNDMSK, READ MASK
RRETMSK=RRETMSK, RETURN FROM READ
WSNDMSK=WSNDMSK, WRITE MASK
WRETMSK=WRETMSK, RETURN FROM WRITE
ESNDMSK=ESNDMSK,
ERETMSK=ERETMSK,
ERRNO=ERRNO, (Specify ERRNO field)
RETCODE=RETCODE, (Specify RETCODE field)
ECB=MY_ECB, MAIN TASK EMB
ERROR=ERROR, Abend if Macro error
TASK=MYTIE,
MF=(E,MY_PARM)
thisocket.Socket(SOCK_STREAM,FD_READ|FD_WRITE|FD_CONNECT,NULL,AF_INET);
if(thisocket.Bind(thisocket.port,ipaddr) == 0)
error_code = GetLastError();
thisocket.GetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val_ptr, SOL_SOCKET);
if(thisocket.SetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val, SOL_SOCKET) == 0)
error_code = GetLastError();
|
|
|
|
|
i download this program from the following link
http://www.codeproject.com/Articles/3061/Creating-a-Serial-communication-on-Win32
i use this program with a balance indicator connecting to the serial port
the program working very well with a type of balance which is Toledo but when using the program with balance
indicator of IQ plus 710 of company ricelake
the read from the indicator repeated
like this
*) 13600 kg *) 13600 kg *) 13600 kg
in the configuration of the indicatore there is not a parameter value of the number of stop bits
what can be the problem ???????????
in the code of C++ i have a variable for the number of stop bits
configSerial_.ByteSize = 7;
configSerial_.StopBits = ONESTOPBIT;
configSerial_.Parity = EVENPARITY;
would you please give me the help for the true setting of paramters
|
|
|
|
|
If you receive valid data (and '13600 kg' looks valid), your serial parameters are correct. The data are repeated because the balance sends them. A quick search finds the manual[^] that states on page 70:
Quote: If continuous transmission is configured for the EDP
or printer port (STREAM parameter on the SERIAL
menu), the IQ plus 710 sends data using the
Consolidated Controls serial data format shown in
Figure 10-1
|
|
|
|
|
i do recieve a valid data but when i use Hyper Terminal and configure it to recieve data from the balance it give one value not repeated .
the balance sends data continousely but in my program
i read the data and write it in the recieved Text Box
this program i used it with Toledo Balance the program works very well and the read data not repeated
i think three is something must be done !!!!
|
|
|
|
|
Let me guess a little bit.
Your balance is sending data continuously as CR terminated lines (C style syntax, \r is CR):
*) 13600 kg\r*) 13600 kg\r*) 13600 kg\r
Because the lines are only CR terminated (not CR-LF), Hyperterminal will not print the next data set on a new line but overwrite the current one. That is: You did not see what you get. This can be changed by configuring HyperTerminal:
Properties (for active connection) - Configuration tab - ASCII configuration button - Append line feed at end of line upon receiving check box (I tried to translate the names from my local version of HyperTerminal). When enabling this option, you will also see repeated data in HyperTerminal.
What you can do is configuring the balance (disable continuous mode, optional enable sending CR-LF with each line) or write code that can handle the data.
To receive such data, your code should read and store the serial bytes until a CR is received. When this happens, copy the string to the text box and resume receiving.
|
|
|
|
|
thanks ENG. Jochen Arndt for your interest
look eng. Jochen
i want to read only one value that is express the balance reading and i want to use this reading
after that to a bussiness application which i developed using PowerBuilder 10.5
i am a powerBuilder Programmer and my experience in c++ is less than powerBuider
i search for a progarm to read from serial port and i found this program
i have changed the program to call a powerbuilder function that i send the read data to it
the program works very well with Toledo Balance as i mentioned and i install the program in a site which contain Toledo Balance
Toledo Balance also send data continousely but i get only on reading
but the iq plus make the problem as i expalined
i want you to give me a hand in the C++ Program if there is someting wrong
|
|
|
|
|
I had a look on the sources of the example program: It reads all available serial data and puts them to the edit box. But you are only interested in a single line. So you must modify the code to get the parts you want.
A quick and dirty solution would be truncating the received data at the first CR or LF byte and stop receiving. A better solution would be doing this inside the thread using a buffer that is overwritten with each new line and provide some data exchange mechanism between the receiving thread and your application's main thread.
|
|
|
|
|
dear eng:Jochen Arndt
i am trying your idea now
but the problem still happen
would you please give me hand ?
|
|
|
|
|
Sorry for my late reply.
I can't help without seeing your code. I suggest to write a new question showing the relevant code part and explaining the problem. So others may help also.
|
|
|
|
|
i am trying to cut string from a pattern like this
@) 1450kg @) 1450kg @) 1450kg
i m trying to cut from the 4th chatacter to the 10th chatacter
var mess contain the chatacter string
i enter the code like this
char mess[MAX_MESSAGE];
unsigned int lenBuff = MAX_MESSAGE;
unsigned long lenMessage;
static CString outPut;
outPut =mess ;
std::string str1 ;
str1=outPut ;
str1 = str1.substr (4,10); /////
CString cs(str1.c_str());
outPut=cs ;
strcpy(mess, outPut);
is this code part is true ???????????????
|
|
|
|
|
Why do you copy the data using so many vars? You should really learn about string operations in C/C++.
The CString class has a constructor that accepts a pointer to a char* string and a length. So you can simply copy the required number of characters:
CString strCut(mess + 3 , 6);
This will copy 6 characters from offset 3 of mess to strCut . Note that offset 3 points to the 4th character.
|
|
|
|
|
thanks for reply eng.Jochen Arndt
in this example if i want to cut from 4th character to the kg position which can be dynamic
@) 1450kg @) 1450kg @) 1450kg
how can i get the position of kg
i use this
outPut =mess ; //////
//------------------
std::string str1 ;
str1=outPut ;
unsigned pos = str1.find("KG");
str1 = str1.substr (4,pos - 1);
CString cs(str1.c_str());
outPut=cs ;
strcpy(mess, outPut);
is this code is true
|
|
|
|
|
Still wrong. As I told you, indexes are zero-based. So you must use 3 as start index. To get the length, subtract the start position from the position of 'kg'. Also there is no need to mix CString and std::string :
CString cs(mess); int nStart = 3; int nStop = cs.Find("kg"); cs = cs.Mid(nStart, nEnd - nStart);
If you want to get numeric values from strings, use the atoi() function:
int nWeight = atoi(mess + 3);
The atoi() function will parse the string stopping at the first non-digit char and return the converted value.
|
|
|
|
|
i tryed this code
char mess[MAX_MESSAGE];
unsigned int lenBuff = MAX_MESSAGE;
unsigned long lenMessage;
static CString outPut;
CString cs(mess); // copy mess to CString object
int nStart = 3; // start at 4th character
int nStop = cs.Find("kg"); // get position of 'kg'
cs = cs.Mid(nStart, nStop - nStart);
//////--------------------------------------------
outPut=cs ;
strcpy(mess, outPut); /////
i finally put the outPut string in the mess character
is this code true
|
|
|
|
|
Again: Why did you use the std::string outPut object?
You can simply copy the extracted sub-string from the CString to mess.
Overall, I can't say if the code is 'true'. You must know what should be done. Check the extracted value using a debugger or printing it out. If it is what you want, you are finished. Otherwise change your code until you get what you want.
|
|
|
|
|
Hi,
I like to gather some coding guideline tools for C. More specific for integration into a CI system showing us some statistics of the code quality.
Can anyone post some suggestions, eventually with feedback or experience about the tool?
regards.
T.
|
|
|
|
|
topcatalpha wrote: More specific for integration into a CI system
What's a CI system ?
Anyway, coding guidelines are quite subjective, google for a few of them and pick whatever looks nice and applicable to your organization (or yourself).
For example, the IBM[^] one looks good.
Nihil obstat
|
|
|
|
|
CI = Continious Integration.
Well we reviewed some tools but it would be nice if we had some feedback from users who are actually using them.
thx,
K
|
|
|
|
|
Hi, i have the following problem:
I have a process which uses PlaySoundA[^] WINAPI function to play a specific sound (let's be it "c:\test.wav"). So the process has already loaded the needed "winmm.dll"
I want to play the same sound when the DLL is injected into the process, so the code looks like:
#define WINVER 0x600
#define _WIN32_WINDOWS 0x600
#define _WIN32_WINNT 0x600
#include <windows.h>
typedef bool __stdcall (*psfunc)(LPCTSTR pszSound, HMODULE hmod, DWORD fdwSound);
void play() {
psfunc ps;
HMODULE winmm = GetModuleHandle("winmm");;
ps = (psfunc)GetProcAddress(winmm, "PlaySoundA");
ps("c:\\test.wav", 0, SND_FILENAME | SND_ASYNC);
}
BOOL __stdcall DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
OutputDebugString("play before");
play();
OutputDebugString("play after");
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
The dll is injected correctly via CreateRemoteThread & LoadLibrary.
But the sound is never played and the dll is blocking at the call of
ps("c:\\test.wav", 0, SND_FILENAME | SND_ASYNC);
Trying to exit the process freezes too because of the blocking thread.
Why does it never return? Procss Monitor doesn't show any error.
How can I solve this?
|
|
|
|
|
|
Oh, I didn't see that.
So I called the function via CreateRemoteThread too and it's working. Thank you!
It would be nice to know what things are allowed/disallowed in DllMain .
|
|
|
|
|
Furblog Sidloth wrote: It would be nice to know what things are allowed/disallowed in DllMain . I agree, the documentation could be better. However, my understanding is that you should not do anything more than initialise the odd static variable or class, and save a handle to the DLL itself. Anything that takes you out of DllMain is not allowed and can lead to problems - as you already discovered.
Use the best guess
|
|
|
|
|
Not only that he has no error checking....
==============================
Nothing to say.
|
|
|
|
|
Seems to be fairly standard these days.
Use the best guess
|
|
|
|