Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - stefan63

Pages: [1]
1
Hello people,
Until now i worked under DOS only (TurboPascal) and for my (RS232) purposes i used
direct port access. Under WinXP and with FreeBasic i want to use standard access
"OPEN COM ....." , but this is too new for me.  What confuses me:
  - how i can check is or not new byte arrived(under DOS i have interrupt)? Or here is another principle?
  - when sending - can i send byte by byte (and how to check is sended or still not  previous byte, under DOS i use interrupt)? Or i must output to "file" whole packed?
  - If "OPEN COM" is for opening , which command is for port closing - "CLOSE filenum" ?
Thank You and regards,
Stefan


 

2
Workplace from where i started:
 - hardware PLC( industrial controller FATEK) is connected to PC via cable. On PC is running FaconServer - tool from FATEK, which is
DDE server . MSExcel is running too. Some cell in Excel is defined as =FaconSvr|Channel0.Station1.Group0!'D1' .
When D1 changes , this change is visible in Excel. With some macros one can change back this value from Excel to PLC.

So my testcode can do  the same ;)  - function RETRIEVEmyDDEitem("D1") reads value of D1 from FaconSvr, function
CHANGEmyDDEitem("D1",120) sets D1 to be 120.

This is very little part of DDE, i suppose Excell uses more complicated DDE functions, most important - CALLBACK mechanism.
In my code CALLBACK is wrongly defined and used.I'll work on this.
regards.


regards,

3
Freebasic / Re: DDE on FreeBasic? final message
« on: December 01, 2006 »
I found sintax , which is good for DDE library , here is my test program (tested with Facon sever, see above), both variants of POKE are working.
Hope this will be helpfull for someone:
Code: [Select]


#DEFINE WIN_INCLUDEALL
option explicit


#include once "windows.bi"
''#inclib "libuser32.dll"

'declare function setstateDDE(i as integer) as integer
declare function RETRIEVEmyDDEitem(byval itemname as string) as string
declare function DdeCallBack as PFNCALLBACK
declare function CHANGEmyDDEitem(byval itemname as string,byval newmydata as integer) as integer
dim shared state1 (0 to 30 ) as integer

dim shared i as integer

dim shared idInst as long


dim shared myhsz as HSZ,hszMYSERVER as HSZ,hszMYTOPIC as HSZ
dim shared hszMYITEM as HSZ
dim shared MYDDEservername as string
dim shared MYDDEtopicname as string, psz as string,MYDDEitemname as string 'LPTSTR

dim shared MYDDEconnection as HCONV
dim shared d1tmp as integer
dim shared d2tmp as integer
MYDDEservername="FaconSvr"
MYDDEtopicname="Channel0.Station1.Group0"


DdeInitialize(@idInst, DdeCallBack,CBF_FAIL_EXECUTES or CBF_SKIP_ALLNOTIFICATIONS,0)
hszMYSERVER=DdeCreateStringHandle(idInst,MYDDEservername,CP_WINANSI)
hszMYTOPIC=DdeCreateStringHandle(idInst,MYDDEtopicname,CP_WINANSI)
MYDDEconnection=DdeConnect(idInst,hszMYSERVER,hszMYTOPIC,NULL)

'================= d1

print "Retrieve:",RETRIEVEmyDDEitem("D1")
print "Retrieve:",RETRIEVEmyDDEitem("D2")
print "Retrieve:",RETRIEVEmyDDEitem("D1")
d1tmp=valint(RETRIEVEmyDDEitem("D1"))
d2tmp=valint(RETRIEVEmyDDEitem("D2"))
print "sleep1"   
sleep

CHANGEmyDDEitem("D1",d1tmp+1)
CHANGEmyDDEitem("D2",d2tmp+2)
print "sleep2"
sleep
print "Retrieve:",RETRIEVEmyDDEitem("D1")
print "Retrieve:",RETRIEVEmyDDEitem("D2")
print "Retrieve:",RETRIEVEmyDDEitem("D1")

DdeDisconnect(MYDDEconnection)
DdeFreeStringHandle(idInst,hszMYSERVER)
DdeFreeStringHandle(idInst,hszMYTOPIC)
DdeUninitialize(idInst)
sleep
end

function DdeCallBack as PFNCALLBACK
print "MYCALLBACK"
return  NULL
end function   
'===========================
function RETRIEVEmyDDEitem(byval itemname as string) as string
dim md1 as HDDEDATA
dim mysize1 as integer
dim mystringresultptr as ubyte ptr
dim help1ptr as ubyte ptr
dim mystringresult as string
dim myres1 as long
   
MYDDEitemname=itemname
print "ASK="; MYDDEitemname
hszMYITEM=DdeCreateStringHandle(idInst,MYDDEitemname,CP_WINANSI)
md1=DdeClientTransaction( NULL,0,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_REQUEST ,110,@myres1)

mysize1= DdeGetdata(md1,NULL,0,0)
'print "returned data has size=",mysize1
mystringresultptr=allocate(mysize1)
help1ptr=mystringresultptr
DdeGetdata(md1,mystringresultptr,mysize1,0)

mystringresult=""
while (*mystringresultptr)<>0
mystringresult=mystringresult+chr(*mystringresultptr)
mystringresultptr+=1
wend
deallocate(help1ptr)
DdeFreeStringHandle(idInst,hszMYITEM)
DdeFreeDataHandle(md1)
return mystringresult
end function   

'====================

function oldCHANGEmyDDEitem(byval itemname as string,byval newmydata as integer) as integer
dim md1 as HDDEDATA
dim md2 as HDDEDATA
dim md2ptr as HDDEDATA ptr
dim mysize1 as integer
dim mystringresultptr as ubyte ptr
dim help1ptr as ubyte ptr
dim mystringresult as string
dim myres1 as long
dim mystringptr as string ptr
dim mypbyte as PBYTE



MYDDEitemname=itemname
hszMYITEM=DdeCreateStringHandle(idInst,MYDDEitemname,CP_WINANSI)

mystringresult=""
mystringresult=str(newmydata)
'print mystringresult;"*"
mysize1=len(mystringresult)
mysize1+=1
mystringptr= Strptr(mystringresult)
mypbyte=cptr(PBYTE,mystringptr)

print "POKE TO="; MYDDEitemname, mystringresult

'successful POKE
md1=DdeClientTransaction(mypbyte,mysize1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)
DdeFreeStringHandle(idInst,hszMYITEM)

return 0
end function   
'========================

function CHANGEmyDDEitem(byval itemname as string,byval newmydata as integer) as integer
dim md1 as HDDEDATA
dim md2 as HDDEDATA
dim md2ptr as HDDEDATA ptr
dim mysize1 as integer
dim mystringresultptr as ubyte ptr
dim help1ptr as ubyte ptr
dim mystringresult as string
dim myres1 as long
dim mystringptr as string ptr
dim mypbyte as PBYTE
MYDDEitemname=itemname
hszMYITEM=DdeCreateStringHandle(idInst,MYDDEitemname,CP_WINANSI)
mystringresult=""
mystringresult=str(newmydata)
mysize1=len(mystringresult)
mysize1+=1

mystringptr= Strptr(mystringresult)
mypbyte=cptr(PBYTE,mystringptr)

print "POKE TO="; MYDDEitemname, mystringresult
md2=DdeCreateDataHandle(idInst,mypbyte,mysize1,0,hszMYITEM,CF_TEXT,0)

'successful POKE
md1=DdeClientTransaction(md2,-1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)

DdeFreeDataHandle(md2)
DdeFreeStringHandle(idInst,hszMYITEM)
'DdeFreeDataHandle(md1) 'not needed i think
return 0
end function   





4
Freebasic / Re: DDE on FreeBasic?
« on: November 29, 2006 »
Question-At this time - what is wrong in CreateDataHandle
md2=DdeCreateDataHandle(idInst,mypbyte,mysize1,0,hszMYITEM,CF_TEXT,0)
and usage
d1=DdeClientTransaction(@md2,-1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)

I'm reading DDE description in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/dynamicdataexchangemanagementlibrary/dynamicdataexchangemanagementreference/dynamicdataexchangemanagementtransactions/xtyp_advdata.asp

regards

5
Freebasic / Re: DDE on FreeBasic?
« on: November 29, 2006 »
hello Jim,
i tryed my first DDE programm (client) with DDE server from
http://www.fatek.com/Download%20Page/English/Fatek_Server/FaSvr110-ENU.EXE

My successful attempt is PEEK (request)  - function RETRIEVEmyDDEitem ,
and one variant of POKE, second variant of POKE is unsuccessfull and
commented below - both in function CHANGEmyDDEitem.

This unsuccessfull attempt is important - i think that way will be naccassary for othet DDE functions.
I dont know how to include my code in shrinkable widow in post , so i just copied (using "CODE" icon above)

Here is my code:
Code: [Select]

#DEFINE WIN_INCLUDEALL
option explicit


#include once "windows.bi"

declare function RETRIEVEmyDDEitem(byval itemname as string) as string
declare function DdeCallBack as PFNCALLBACK
declare function CHANGEmyDDEitem(byval itemname as string,byval newmydata as integer) as integer
dim shared state1 (0 to 30 ) as integer

dim shared i as integer

dim shared idInst as long


dim shared myhsz as HSZ,hszMYSERVER as HSZ,hszMYTOPIC as HSZ
dim shared hszMYITEM as HSZ
dim shared MYDDEservername as string
dim shared MYDDEtopicname as string, psz as string,MYDDEitemname as string 'LPTSTR

dim shared MYDDEconnection as HCONV
dim shared d1tmp as integer
dim shared d2tmp as integer
MYDDEservername="FaconSvr"
MYDDEtopicname="Channel0.Station1.Group0"


DdeInitialize(@idInst, DdeCallBack,CBF_FAIL_EXECUTES or CBF_SKIP_ALLNOTIFICATIONS,0)
hszMYSERVER=DdeCreateStringHandle(idInst,MYDDEservername,CP_WINANSI)
hszMYTOPIC=DdeCreateStringHandle(idInst,MYDDEtopicname,CP_WINANSI)
MYDDEconnection=DdeConnect(idInst,hszMYSERVER,hszMYTOPIC,NULL)

'================= d1

print "Retrieve:",RETRIEVEmyDDEitem("D1")
print "Retrieve:",RETRIEVEmyDDEitem("D2")
print "Retrieve:",RETRIEVEmyDDEitem("D1")
d1tmp=valint(RETRIEVEmyDDEitem("D1"))
d2tmp=valint(RETRIEVEmyDDEitem("D2"))
print "sleep1"Â  Â  
sleep

CHANGEmyDDEitem("D1",d1tmp+1)
CHANGEmyDDEitem("D2",d2tmp+2)
print "sleep2"
sleep
print "Retrieve:",RETRIEVEmyDDEitem("D1")
print "Retrieve:",RETRIEVEmyDDEitem("D2")
print "Retrieve:",RETRIEVEmyDDEitem("D1")

DdeDisconnect(MYDDEconnection)
DdeFreeStringHandle(idInst,hszMYSERVER)
DdeFreeStringHandle(idInst,hszMYTOPIC)
DdeUninitialize(idInst)
sleep
end

function DdeCallBack as PFNCALLBACK
print "MYCALLBACK"
return  NULL
end function  Â  
'===========================
function RETRIEVEmyDDEitem(byval itemname as string) as string
dim md1 as HDDEDATA
dim mysize1 as integer
dim mystringresultptr as ubyte ptr
dim help1ptr as ubyte ptr
dim mystringresult as string
dim myres1 as long
  Â  
MYDDEitemname=itemname
print "ASK="; MYDDEitemname
hszMYITEM=DdeCreateStringHandle(idInst,MYDDEitemname,CP_WINANSI)
md1=DdeClientTransaction( NULL,0,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_REQUEST ,110,@myres1)

mysize1= DdeGetdata(md1,NULL,0,0)
print "returned data has size=",mysize1
mystringresultptr=allocate(mysize1)
help1ptr=mystringresultptr
DdeGetdata(md1,mystringresultptr,mysize1,0)

mystringresult=""
while (*mystringresultptr)<>0
mystringresult=mystringresult+chr(*mystringresultptr)
mystringresultptr+=1
wend
deallocate(help1ptr)
DdeFreeStringHandle(idInst,hszMYITEM)
DdeFreeDataHandle(md1)
return mystringresult
end function  Â  

'====================

function CHANGEmyDDEitem(byval itemname as string,byval newmydata as integer) as integer
dim md1 as HDDEDATA
dim md2 as HDDEDATA
dim md2ptr as HDDEDATA ptr
dim mysize1 as integer
dim mystringresultptr as ubyte ptr
dim help1ptr as ubyte ptr
dim mystringresult as string
dim myres1 as long
dim mystringptr as string ptr
dim mypbyte as PBYTE



MYDDEitemname=itemname
hszMYITEM=DdeCreateStringHandle(idInst,MYDDEitemname,CP_WINANSI)

mystringresult=""
mystringresult=str(newmydata)
'print mystringresult;"*"
mysize1=len(mystringresult)
mysize1+=1
mystringptr= Strptr(mystringresult)
mypbyte=cptr(PBYTE,mystringptr)

print "POKE TO="; MYDDEitemname, mystringresult

'successful POKE
md1=DdeClientTransaction(mypbyte,mysize1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)

'UNSUCCESSFUL poke
'md2=DdeCreateDataHandle(idInst,mypbyte,mysize1,0,hszMYITEM,CF_TEXT,0)
''debug backread
'mysize1= DdeGetdata(md2,NULL,0,0)
'print "md2-datasize=",mysize1Â  Â 'returns correct value
'mystringresultptr=allocate(mysize1)
'help1ptr=mystringresultptr
'DdeGetdata(md2,mystringresultptr,mysize1,0) ''
'mystringresult=""
'while (*mystringresultptr)<>0
'Â  Â ' print "~",*mystringresultptr,"~"
'mystringresult=mystringresult+chr(*mystringresultptr)
'mystringresultptr+=1
'wend
'deallocate(help1ptr)
'print "md2 string=";mystringresult;"*"  'string is  correct
''end debug backread

'different variants tryed without success
'mypbyte=cptr(PBYTE,@md2)
'd1=DdeClientTransaction(@md2,-1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)
'md1=DdeClientTransaction(mypbyte,-1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)
'md1=DdeClientTransaction(mypbyte,mysize1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)
'md1=DdeClientTransaction(md2ptr,-1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)
'md1=DdeClientTransaction(mypbyte,-1,MYDDEconnection,hszMYITEM,CF_TEXT,XTYP_POKE ,110,@myres1)
'DdeFreeDataHandle(md2)


DdeFreeStringHandle(idInst,hszMYITEM)

DdeFreeDataHandle(md1)
return 0
end function  Â  


6
Freebasic / Re: DDE on FreeBasic?
« on: November 26, 2006 »
Thank You Jim,
nice answer.
I'll study how it's done on other laguages and will ask You later - can i?
It is not very clear for me DDE prrocess at whole, so maybe i'll need more time.
regards
Stefan

7
Hi all,
Can anybody point to some article, which describes usage of DDE in FreeBasic?
I have DDE server running (Excel works with him) - how to communicate with server from FreeBasic?
regards,
Stefan

Pages: [1]