Click here to Skip to main content
16,016,192 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: To disable a tab Pin
Hamid_RT24-Oct-06 2:35
Hamid_RT24-Oct-06 2:35 
AnswerRe: To disable a tab Pin
Hamid_RT24-Oct-06 2:35
Hamid_RT24-Oct-06 2:35 
AnswerRe: To disable a tab Pin
David Crow24-Oct-06 2:51
David Crow24-Oct-06 2:51 
QuestionCPPUNIT_PLUGIN_IMPLEMENT linker error in .NET VC7 Pin
jayart24-Oct-06 0:36
jayart24-Oct-06 0:36 
AnswerRe: CPPUNIT_PLUGIN_IMPLEMENT linker error in .NET VC7 Pin
Naveen24-Oct-06 0:47
Naveen24-Oct-06 0:47 
GeneralRe: CPPUNIT_PLUGIN_IMPLEMENT linker error in .NET VC7 Pin
jayart24-Oct-06 1:00
jayart24-Oct-06 1:00 
GeneralRe: CPPUNIT_PLUGIN_IMPLEMENT linker error in .NET VC7 Pin
Naveen24-Oct-06 1:06
Naveen24-Oct-06 1:06 
Questionfrom windows to linux Pin
dorbeck24-Oct-06 0:21
dorbeck24-Oct-06 0:21 
I have written the following code in visual C++. it worked like it should. But know i want it to work in linux. I thought that C++ worked the same under every platform. But I included for example winsocket.h en wsock32.lib. Do I have to rewrite my complete code or is there a nother way to let my code work? I use Vi in linux.

in linux I include these files:
#include <fstream.h>
#include <sstream.h>
#include <iostream.h>
#include <logger.h>
#include <net socket.h="">
#include <process.h>
#include <stringutil.h>
#include <typenames.h>

#include <sys socket.h="">
#include <sys time.h="">

in windows i included those files:

#include "Socket.h"

#include <iostream>
#include <process.h>
#include <sstream>

#include <fstream>
#include <string>
#include <windows.h>
#include <winsock.h>
#include <winsock2.h>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>



using namespace std;

double setpoint = 20;


int open_connection(const string& hostname, int portnr) {

SOCKET mySocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in itsTCPAddr;
memset (&itsTCPAddr, 0, sizeof(itsTCPAddr));
itsTCPAddr.sin_family = AF_INET;

unsigned int IPbytes;

// try if hostname is hard ip address
if ((IPbytes = inet_addr(hostname.c_str())) == INADDR_NONE) {

// No, try to resolve the name
struct hostent* hostEnt; // server host entry
if (!(hostEnt = gethostbyname(hostname.c_str()))) {

return (-2);
}


// Check type
if (hostEnt->h_addrtype != AF_INET) {
return (-3);
}

memcpy (&IPbytes, hostEnt->h_addr, sizeof (IPbytes));
}
memcpy ((char*) &itsTCPAddr.sin_addr.s_addr, (char*) &IPbytes, sizeof(IPbytes));

itsTCPAddr.sin_port = htons(portnr);

int result = connect(mySocket, (struct sockaddr *)&itsTCPAddr, sizeof(struct sockaddr_in));
return (mySocket);

}



struct StuurUitlezen { // (14 bytes) Declare Modbus_TCP struct type
short TransactionIdentifier; // = 2 bytes

short ProtocolIdentifier; // = 2 bytes
short Length; // = 2 bytes
byte UnitIdentifier; // = 1 byte

// -modbus
byte Function3; //:15 = 1 bytes
short ReferenceNumber; // = 2 bytes
short WordCount; // = 2 bytes

} StuurUitlezen_t;


///////////////////////////////////////////////////////////////////////

#pragma pack(1)
struct StuurUitpt { // (14 bytes) Declare Modbus_TCP struct type

short TransactionIdentifie; // = 2 bytes
short ProtocolIdentifie; // = 2 bytes
short Lengt; // = 2 bytes
byte UnitIdentifie; // = 1 byte

// -modbus = 6 bytes
byte Functio; //:15 = 1 bytes
byte ByteCount; // = 1 byte
short T1; // = 2 bytes
short T2; // = 2 bytes
short T3; // = 2 bytes
short T4; // = 2 bytes
short T5; // = 2 bytes
short T6; // = 2 bytes
short T7; // = 2 bytes
WORD Data[22]; // = rest data 22 bytes over


} StuurUitpt_t;

/////////////////////////////////////////////////////////////////////////


int main() {



WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;

nRet = WSAStartup(wVersionRequested, &wsaData);
if (wsaData.wVersion != wVersionRequested)
{
fprintf(stderr,"\n Wrong version\n");
return(-1);
}



int h = 0;
while(h < 10) {
h++;




int connection;
connection = open_connection("10.151.218.1", 502);

struct StuurUitlezen demand;

demand.TransactionIdentifier = htons(0);
demand.ProtocolIdentifier = htons(0);
demand.Length = htons(8); //moeten 4 bits zijn
demand.UnitIdentifier = 01;
demand.Function3 = 3;
demand.ReferenceNumber = 0;
demand.WordCount = htons(18);

int result = send(connection, (char*)&demand, sizeof(demand), 0);


struct StuurUitpt receiv;

receiv.TransactionIdentifie;
receiv.ProtocolIdentifie;
receiv.Lengt;
receiv.UnitIdentifie;
receiv.Functio;
receiv.ByteCount;
receiv.T1;
receiv.T2;
receiv.T3;
receiv.T4;
receiv.T5;
receiv.T6;
receiv.T7;
receiv.Data;

int uitpt = recv(connection, (char*)&receiv, sizeof(receiv), 0);


short HT1 = htons(receiv.T1);
short HT2 = htons(receiv.T2);
short HT3 = htons(receiv.T3);
short HT4 = htons(receiv.T4);
short HT5 = htons(receiv.T5);
short HT6 = htons(receiv.T6);
short HT7 = htons(receiv.T7);

double RT1 = (HT1 - 16384) / 327.6;
double RT2 = (HT2 - 16384) / 327.6;
double RT3 = (HT3 - 16384) / 327.6;
double RT4 = (HT4 - 16384) / 327.6;
double RT5 = (HT5 - 16384) / 327.6;
double RT6 = (HT6 - 16384) / 327.6;
double RT7 = (HT7 - 16384) / 327.6;

fprintf(stderr,"RT1: %3.2f\n", RT1);
fprintf(stderr,"RT2: %3.2f\n", RT2);
fprintf(stderr,"RT3: %3.2f\n", RT3);
fprintf(stderr,"RT4: %3.2f\n", RT4);
fprintf(stderr,"RT5: %3.2f\n", RT5);
fprintf(stderr,"RT6: %3.2f\n", RT6);
fprintf(stderr,"RT7: %3.2f\n", RT7);

//Temperatuur is readed, from this point send


double MaxTemp = setpoint + 0.5;
double MinTemp = setpoint - 0.5;

int RTH1;
int RTH2;
int RTH3;
int RTH4;
int RTH5;
int RTH6;
int RTH7;


if (RT1 > MaxTemp) { RTH1 = 1; };
if (RT2 > MaxTemp) { RTH2 = 1; };
if (RT3 > MaxTemp) { RTH3 = 1; };
if (RT4 > MaxTemp) { RTH4 = 1; };
if (RT5 > MaxTemp) { RTH5 = 1; };
if (RT6 > MaxTemp) { RTH6 = 1; };
if (RT7 > MaxTemp) { RTH7 = 1; };

if (RT1 < MinTemp) { RTH1 = 0; };
if (RT2 < MinTemp) { RTH2 = 0; };
if (RT3 < MinTemp) { RTH3 = 0; };
if (RT4 < MinTemp) { RTH4 = 0; };
if (RT5 < MinTemp) { RTH5 = 0; };
if (RT6 < MinTemp) { RTH6 = 0; };
if (RT7 < MinTemp) { RTH7 = 0; };


struct Modbus_TCP { // (14 bytes) Declare Modbus_TCP struct type

short TransactionIdentifiers; // = 2 bytes
short ProtocolIdentifiers; // = 2 bytes
short Lengths; // = 2 bytes
byte UnitIdentifiers; // = 1 byte

// -modbus
byte FunctionForceMultipleCoilss; //:15 = 1 bytes
short ReferenceNumbers; // = 2 bytes
short BitCounts; // = 2 bytes
byte ByteCounts; // = 1 byte
byte Datas; // = 1 byte (hier bepaal je wat aan en uit gaat)

} Modbus_TCP_t;


connection = open_connection("10.151.218.2", 502);

struct Modbus_TCP command;

command.TransactionIdentifiers = htons(0);
command.ProtocolIdentifiers = htons(0);
command.Lengths = htons(8); //moeten 4 bits zijn
command.UnitIdentifiers = 01;
command.FunctionForceMultipleCoilss = 15;
command.ReferenceNumbers = htons(16);
command.BitCounts = htons(6);
command.ByteCounts = 01;
command.Datas = RTH1+(RTH2*2)+(RTH3*4)+(RTH4*8)+(RTH5*16)+(RTH6*32)+(RTH6*64);

result = send(connection, (char*)&command, sizeof(command), 0);

Sleep (5000);

}

return 0;

}


Errors in linux:
Which are A lot.



make all-recursive
make[1]: Entering directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug'
Making all in src
make[2]: Entering directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/src'
if /usr/bin/g++32 -DHAVE_CONFIG_H -I. -I/home/tauber/LOFAR/MAC/APL/StsMisc/src -I.. -I/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/pkginc -I/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/pkgbldinc -I/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug -I/home/tauber/LOFAR/MAC/APL/StsMisc/include -DUSE_DEBUG -DUSE_THREADS -pthread -D_GNU_SOURCE -I/usr/local/log4cplus/gnu/include -I/home/tauber/LOFAR/installed/gnu_debug/include -g -W -Wall -Woverloaded-virtual -Wno-unknown-pragmas -MT ModBusRead.o -MD -MP -MF ".deps/ModBusRead.Tpo" -c -o ModBusRead.o /home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc; \
then mv -f ".deps/ModBusRead.Tpo" ".deps/ModBusRead.Po"; else rm -f ".deps/ModBusRead.Tpo"; exit 1; fi
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:31: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:34: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:49: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:52: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:53: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:61: syntax error before `[
' token
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:68: ISO C++ forbids
declaration of `hostname' with no type
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc: In function `int
open_connection(int, std::string&, int)':
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:70: `mySocket' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:70: (Each undeclared
identifier is reported only once for each function it appears in.)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:78: request for member `
c_str' in `hostname', which is of non-aggregate type `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:78: `inet_addr' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:82: request for member `
c_str' in `hostname', which is of non-aggregate type `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:82: `gethostbyname'
undeclared (first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:89: invalid use of
undefined type `struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:81: forward declaration of
`struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:93: invalid use of
undefined type `struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:81: forward declaration of
`struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:99: warning: unused
variable `int result'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc: In function `int main()':
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:108: `WORD' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:108: syntax error before `
=' token
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:109: `WSADATA' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:112: `wVersionRequested'
undeclared (first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:112: `wsaData' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:112: `WSAStartup'
undeclared (first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:127: invalid conversion
from `const char*' to `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:127: could not convert `
502' to `std::string&'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:68: in passing argument 2
of `int open_connection(int, std::string&, int)'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:129: aggregate `
StuurUitlezen demand' has incomplete type and cannot be defined
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:147: `struct StuurUitpt'
has no member named `UnitIdentifie'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:148: `struct StuurUitpt'
has no member named `Functio'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:149: `struct StuurUitpt'
has no member named `ByteCount'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:157: `struct StuurUitpt'
has no member named `Data'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:225: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:228: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:231: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:232: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:237: invalid conversion
from `const char*' to `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:237: could not convert `
502' to `std::string&'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:68: in passing argument 2
of `int open_connection(int, std::string&, int)'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:244: `struct
main()::Modbus_TCP' has no member named `UnitIdentifiers'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:245: `struct
main()::Modbus_TCP' has no member named `FunctionForceMultipleCoilss'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:248: `struct
main()::Modbus_TCP' has no member named `ByteCounts'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:249: `struct
main()::Modbus_TCP' has no member named `Datas'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:253: `Sleep' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:160: warning: unused
variable `int uitpt'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:234: warning: unused
variable `main()::Modbus_TCP Modbus_TCP_t'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:144: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:145: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:146: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:150: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:151: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:152: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:153: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:154: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:155: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:156: warning: statement
with no effect
make[2]: *** [ModBusRead.o] Error 1
make[2]: Leaving directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug'
make: *** [all] Error 2


It would help a lot if somboddy knows any answer


thnx, Dorbeck
AnswerRe: from windows to linux Pin
Naveen24-Oct-06 0:37
Naveen24-Oct-06 0:37 
AnswerRe: from windows to linux Pin
kakan24-Oct-06 2:50
professionalkakan24-Oct-06 2:50 
GeneralRe: from windows to linux Pin
dorbeck24-Oct-06 2:56
dorbeck24-Oct-06 2:56 
QuestionCheckbox control Pin
fabiotriolo23-Oct-06 23:53
fabiotriolo23-Oct-06 23:53 
AnswerRe: Checkbox control Pin
Cedric Moonen24-Oct-06 0:06
Cedric Moonen24-Oct-06 0:06 
AnswerRe: Checkbox control Pin
Mila02524-Oct-06 0:31
Mila02524-Oct-06 0:31 
Questionhelp me Pin
alphaxz23-Oct-06 23:21
alphaxz23-Oct-06 23:21 
AnswerRe: help me Pin
fat_boy23-Oct-06 23:33
fat_boy23-Oct-06 23:33 
Questionfatal error C1083 : Cannot open include file: 'uxtheme.h' Pin
NiceNaidu23-Oct-06 23:10
NiceNaidu23-Oct-06 23:10 
AnswerRe: fatal error C1083 : Cannot open include file: 'uxtheme.h' Pin
Naveen24-Oct-06 0:41
Naveen24-Oct-06 0:41 
AnswerRe: fatal error C1083 : Cannot open include file: 'uxtheme.h' Pin
Hamid_RT24-Oct-06 2:43
Hamid_RT24-Oct-06 2:43 
Questiontabstop2 Pin
Desmo1623-Oct-06 22:38
Desmo1623-Oct-06 22:38 
AnswerRe: tabstop2 Pin
tanvon malik24-Oct-06 0:03
tanvon malik24-Oct-06 0:03 
Questionmacro representing Visual C++ compiler Pin
manustone23-Oct-06 22:33
manustone23-Oct-06 22:33 
AnswerRe: macro representing Visual C++ compiler Pin
Cedric Moonen23-Oct-06 22:50
Cedric Moonen23-Oct-06 22:50 
GeneralRe: macro representing Visual C++ compiler Pin
manustone23-Oct-06 23:04
manustone23-Oct-06 23:04 
GeneralRe: macro representing Visual C++ compiler Pin
Sceptic Mole24-Oct-06 2:50
Sceptic Mole24-Oct-06 2:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.