Oprettet fre. d. 05. marts 2010 kl. 20:58:44

op1
op1 (11.505 point. Point ude: 90)

Oppdatering av Private Sub

Hvordan oppdaterer man Private Sub i VB i Access uten å måtte bruke hendelseprosedyrer på objekter i Forms?
I mitt tilfelle dreier det som å benytte bits over Modbus TCP. Disse har jeg i VB men jeg får dem ikke til å utføre Ptivte Subs i VB.

Skrevet lør. d. 06. marts 2010 kl. 09:53:52| #1

terry
terry (244.617 point)
Looking at your last question http://www.eksperten.dk/ (...)

your expecting something which isnt possible

Skrevet lør. d. 06. marts 2010 kl. 10:08:47| #2

terry
terry (244.617 point)
Access uses a timer event to trigger code at specific intervals and that the answer which you were previoulsy given.
Without knowing anything about Modbus etc its not easy to make suggestions  on how to solve your problem.

Can you give a short description of what your trying to do and a little about Modbus please?

Skrevet lør. d. 06. marts 2010 kl. 13:44:15| #3

terry
terry (244.617 point)
what hardware are receiving data from?

More info please...

Skrevet lør. d. 06. marts 2010 kl. 16:30:33| #4

op1
op1 (11.505 point)
Hei Terry
Tidligere spørsmål handlet om tidstyret kontroll av Private Subs.
Det jeg ønsker her er hendels-styrt kontroll av Private Subs utenom den kontroll man har ved å knytte Private Subs til objekter i Forms.

  Modbus er en industriell kommunikasjonsprotokoll som tidligere kun ble utført over seriell-port på PC/PLC. Da Ethernet kom utviklet man Modbus slik at den kan kommunisere over vanlig "kontornettverk". Derav navnet Modbus TCP. Der etter ble det utviklet Active-X som gjør at man benytte Modbus-TCP direkte inn i applikasjoner som støtter bruk av Active-X. Access støtter bruk av Active-X. Derfor kan man skrive kode i VB som gjør at man har dynamisk og kontrollerbar data-flyt mellom en controller-device som støtter Modbus-TCP og Access. Modbus TCP visker ut skillet mellom prosessdata og øvrig data-bruk.

  Nedenfor vises et eksempel på Private Sub som kontrolleres med Button i et skjema, men dette skulle gjerne vært utført med et bit som kommer fra min kontroll-device. ( Koyo05 PLC. )


Private Sub LoggVektverdi_Click()
   
If KvVeiingAvsl = 1 And VarekodeVeiedata > 0 Then

Me.DatoVeiedata = Date
Me.TidVeiedata = Time()
Me.VektverdiVeiedata = (V1510 * 100) + V1512

  End If


End Sub

Skrevet lør. d. 06. marts 2010 kl. 18:06:45| #5

terry
terry (244.617 point)
Hi op1

I understand that its a comms. protocol.

I must admit I dont quite understand the language your writing. Is it Norwegian?

Are you trying to execute the sub ( LoggVektverdi_Click) without having to click on the object LoggVektverdi?

You can execute by writing

LoggVektverdi_Click in code and as it is Private then it has to be within the forms module.

Do you want to execute the sub when a data bit is received by the ActiveX control?

If the ActiveX control is on the form then just writing

LoggVektverdi_Click  in one of the control events should work.

Skrevet lør. d. 06. marts 2010 kl. 19:40:04| #6

op1
op1 (11.505 point)
Hi
Yes, I write in Norwegian.
"Are you trying to execute the sub ( LoggVektverdi_Click) without having to click on the object LoggVektverdi?"  Yes

"Do you want to execute the sub when a data bit is received by the ActiveX control?"  Yes, this is exactly what I mean.

You suggest: LoggVektverdi_Click  in one of the control events should work.
I do not understand. In this statement there is no connection between my Modbustag and the sub to be executed. LoggVektverdi is name of a button in my form.
I hoped I could replace LoggVektverdi with  the name of one of my Modbus-tags, but I cant make it working. May be it is outside the rules of VB? It is no problem to use the Modbustags to show the value, change colour etc.

Skrevet lør. d. 06. marts 2010 kl. 20:55:52| #7

terry
terry (244.617 point)
OK I think I understand what your after


Are you using the Winsock control?


I'll get back to you tomorrow, going to see some TV

Skrevet lør. d. 06. marts 2010 kl. 21:13:26| #8

op1
op1 (11.505 point)
Hi
Winsoc controll? I dont know what it is. If it can help: The connection between my Modbus-device ( PLC ) is done by a Active-X, innstalled in my Access-application. This Active-X makes i possible to write certain code i VB to achive data to/from my PLC. Modbus operates with singel bits or 16 bits signed integers. In this case PLC operates as a server and Access as a client. Each time the Sub is executed data will be read/written from/to my PLC. Each Modbus-tag is named exclusively in VB-code. In the code-example above V1510 og V1512 are names on two 16 bits Modbustags.

Skrevet søn. d. 07. marts 2010 kl. 09:19:17| #9

terry
terry (244.617 point)
Winsock is also a protocol, I was thinking that ModBus maybe used it.

http://en.wikipedia.org/ (...)

Anyway if I have undertstood your problem your trying to run the code in a sub which is on a form.

As I mentioned previously Private functions and Subs can only be used in the module (form/code) in which it exits.

But you can make a Public function and call this from any module.

I assume that the ActiveX control has a code module wher ethere is a function which receives the data,is that correct?
I would think that is necessary otherwise I cant see how you would receive data.


Try this

Move the code from LoggVektverdi_Click into a new function named MyFunction.


Private Sub LoggVektverdi_Click()

  MyFunction

End Sub


Public function MyFunction()

     
If KvVeiingAvsl = 1 And VarekodeVeiedata > 0 Then

  Me.DatoVeiedata = Date
  Me.TidVeiedata = Time()
  Me.VektverdiVeiedata = (V1510 * 100) + V1512

End If


End Function

Remember to save the forms and modules you alter.

Now you can call MyFunction from other forms modules like this

forms!NamOfFormGoesHere.MyFunction

Skrevet søn. d. 07. marts 2010 kl. 21:29:28| #10

op1
op1 (11.505 point)
Hi Terry

Thank you for suggestion, but I cant see your eksample makes differense. I made it working but still the function is not triggered by one of my Modbustags. Below I show you an eksample on how to get 8 bits from my Modbus-device. The names on the left side of = are the names beeing used in Access. Names on right side of = are names bound to the VB-syntax for my Active-X. What I want is one or more of theese to execute a Private Sub or a Function when they change their value from 0 to 1.

To call for data from Modbus-device the code goes like this:

Private Sub Form_Timer()

        Dim nRegData(6) As Integer    ' register data buffer (size as necessary)
        Dim nCoilData(7) As Integer  ' coildatabuffer
        Dim e As Integer              ' return error
        Dim S As String              ' string variable used for formatting reg. data
 
   
    e = SMTX1.MbReadCoilStatus(1, 3072, 8, nCoilData(0)) 'LeserC0-C7
    Tara = nCoilData(0)
    OpSpjOvBeh = nCoilData(1)
    VeiingPagar = nCoilData(2)
    LuSpjOvBeh = nCoilData(3)
    Brutto = nCoilData(4)
    OpSpjUndBeh = nCoilData(7)

Skrevet man. d. 08. marts 2010 kl. 09:50:16| #11

terry
terry (244.617 point)
You have to appreciate that I know NOTHING other than what I see here about what you are doing so I am trying to get a picture of how your Access database and ModBus work together.


" I made it working but still the function is not triggered by one of my Modbustags"

What is a Modbustags? Where is that in your code?

If the Form_Timer() event and  LoggVektverdi_Click() event are on the same form then you dont need to make a public function. Are they on the same form?

If they are then you just need to add a line of code to call the sub
So after this line

OpSpjUndBeh = nCoilData(7)

add

LoggVektverdi_Click


Your original question was
"Hvordan oppdaterer man Private Sub i VB i Access uten å måtte bruke hendelseprosedyrer på objekter i Forms?"

and thats what I'm trying to asnwer not>

" What I want is one or more of theese to execute a Private Sub or a Function when they change their value from 0 to 1."

Once we can call a sub then I'm sure you can test if the data has changed from 0 to 1.

Skrevet man. d. 08. marts 2010 kl. 10:24:52| #12

op1
op1 (11.505 point)
Hi

Sorry for my inacurate question, but so far as I can see your answer still needs a action to be taken in one or another form-objekt, or am I wrong?

If the Form_Timer() event and  LoggVektverdi_Click() event are on the same form then you dont need to make a public function. Are they on the same form? 
Yes, they are.

This is an eksample on Modbustag: Brutto = nCoilData(4)


When I tried to solve the problem first, I wrote thise code:

Private Sub Brutto = 1()

  Me.DatoVeiedata = Date
  Me.TidVeiedata = Time()
  Me.VektverdiVeiedata = (V1510 * 100) + V1512

End Sub

Why does it not work? I can use the Modbustag Brutto to change colour, show the value, boolean math, but not to perform Privete Subs.  What am I doing wrong?

Skrevet man. d. 08. marts 2010 kl. 10:33:04| #13

terry
terry (244.617 point)
"What am I doing wrong?"

Your not showing/telling me the whole picture :o)

Can you send me your dB? I know I cant test it but maybe seeing your code etc will help.

ekspertenATsanthell.dk

AT = @

Skrevet tir. d. 09. marts 2010 kl. 08:05:28| #14

op1
op1 (11.505 point)
Hi Terry
Thank you for involving your self in my question. I can send you my DB but not as it looks like now. I have to clean it up a little bit. Too much experimental code. There is not much more picture to show, but the main thing I want to discuss is my very first question. According to this question we can imagine theese situations:
Is it possible to execute private Subs on different timeintervalls within the same form?
Is it possible to execute private Subs according to spesfic result from a calculation?
Is it possible to execute private Subs according to logic in boolean calculations?
Is it possible to execute private Subs on bits/bytes-values from other applications like PLC or other connected devices?

May be this is out of range for VB?

Skrevet tir. d. 09. marts 2010 kl. 08:55:38| #15

terry
terry (244.617 point)
Is it possible to execute private Subs on different timeintervalls within the same form?
A form has only one timer event so if you need more no.

"different timeintervalls"?
Well as I stated there is only one timer event but I would think it possible to do differnt things depending on an inteval. Now I havent tried anything like this but I cantsee why it shouldnt work.
Lets say the timer event fiores every 0,5 seconds. In a sub/function you can have what is called a static variable which you could use to increment by (for example) 1 each time the timer event is fired. So if you wanted to do something every 2 seconds you can test what the value is and if its 3 (test before incrementing) then we know that 2 seconds have gone. You can the rest to 0.
As I said thats just an idea which I havent tried.


Is it possible to execute private Subs according to spesfic result from a calculation?
Yes

Is it possible to execute private Subs according to logic in boolean calculations?
I dont see why not, yes

Is it possible to execute private Subs on bits/bytes-values from other applications like PLC or other connected devices?
???
Not sure how to answer this.
Does the ModBus ActiveX control have evenys which fire when it receives data from the PLC? If it does then YES.


If your software has to read data comming from the PLC then again YES.
So the answer seems to be YES.

Skrevet tir. d. 09. marts 2010 kl. 09:01:33| #16

terry
terry (244.617 point)
I have a brother who is kind of an expert with PLC things, he made this sofware www.easydnc.com this sofwatre uses seriel comms. but he has also made things which use the internet (network) using the Winsock control I mentioned.

It has an event which fires when it receives data, so it isnt necessary to use timer events.

This is whathe says>

You have the control on your form.

You have an event called "DataArrival" so if your winsock control was called ws1 your event would look like this:-

Private Sub ws1_DataArrival(HowManyBytes as long)

as soon as any other device sends information to your ip address/port number the code in the DataArrival  event will start executing. You don't need to use a timer, just put your code in that event and it'll start executing as soon as a message arrives.
The first thing you might want to do is read the value of HowManyBytes and that will tell you how long the message from the PLC is. Is the length what you expect ? If it is then just read the message into a string like this

MyString = ws1.GetData


End Sub

Skrevet tir. d. 09. marts 2010 kl. 09:02:12| #17

terry
terry (244.617 point)
I'm going out shortly, back around 12:00

Skrevet tir. d. 09. marts 2010 kl. 12:04:26| #18

op1
op1 (11.505 point)
Hello Terry

Seems to be on the track now.


"Is it possible to execute private Subs according to logic in boolean calculations? I dont see why not, yes"
Could you please give me a short eksample, may be I can do it this way. I have not problems using Modbus-tags in simple boolean calculations.


" Does the ModBus ActiveX control have events which fire when it receives data from the PLC? If it does then YES "
Have sendt a mail to the company developed the Active-X to ask.
www.sapia-inc.com

Skrevet tir. d. 09. marts 2010 kl. 12:19:57| #19

terry
terry (244.617 point)
Give me a boolean calculation


I've just looked at the link www.sapia-inc.com


"Download a demo today and get on with your development.  Do what you do best and leave the Modbus to us."


There must be some example code in these demo modules, havent you looked at them?

Any that work in VB6 should work in Access.

Skrevet tir. d. 09. marts 2010 kl. 12:53:26| #20

op1
op1 (11.505 point)
Hi

Eksample using Modbustag in boolean logic:

Private Sub LoggVektverdi_Click()
   
If KvVeiingAvsl = 1 And VarekodeVeiedata > 0 Then 
  Me.DatoVeiedata = Date
  Me.TidVeiedata = Time()
  Me.VektverdiVeiedata = (V1510 * 100) + V1512
End If
End Sub
'KvVeingAvsl = Modbusvalue ( One bit.)
'LoggVektverdi = Button in my form.
'VarekodeVeiedata = Value to be logged to my table with the other data beeing "Me". Make sure they are all inncluded.


Yes there are lots eksamples to get bits/bytes to/from the Modbus-device.

Skrevet tir. d. 09. marts 2010 kl. 13:07:34| #21

terry
terry (244.617 point)
Now I'm lost again.

You say
"Could you please give me a short eksample, may be I can do it this way. I have not problems using Modbus-tags in simple boolean calculations."

So I thought you wanted an example and I asked for "Give me a boolean calculation" so I could givg eyou an example.

Do you have wa´nt you want now?

Skrevet tir. d. 09. marts 2010 kl. 15:17:50| #22

op1
op1 (11.505 point)
What I meant was en eksample from you how to write at boolean calculation that ends up i execution an Private Sub.

What you got from me was an eksample how I made a boolean tag from Modbus working in a boolean logic in a sub that ends up in a Me-command.

As you still see my private sub must be activated from a button on my form (LoggVektverdi)
You wrote above that Private Subs can be activated ( executed ) as a result from a boolean calculation. Executing a Sub is one thing  Result of the code written within a Sub i another.

Skrevet tir. d. 09. marts 2010 kl. 15:50:01| #23

terry
terry (244.617 point)
op1
I'm going to pass on this quesion shortly as I dont seem to be getting anywhere.

I cant teach you to code, sorry.

I have given an example of how to call a sub/function from your timer event, if you cant manage to put this into practice then I'm afraid its going to take far to long.

To call the sub  LoggVektverdi_Click
you wriet in your code (EXACTLY AS IT IS HERE)

LoggVektverdi_Click


You should try the examples you say are in the demo download

"Yes there are lots eksamples to get bits/bytes to/from the Modbus-device"

Skrevet tir. d. 09. marts 2010 kl. 16:10:28| #24

op1
op1 (11.505 point)
Hi Terry

"You should try the examples you say are in the demo download"
I have no problem to make the demo-code working. I have the all the modbus-data I want innside my Access-application.
The challenge is how to use this data to perform VB-code automatically. As you understand I want to avoid manually actions so much as possible of security-reasons. The hole idea is to use modbus-data to execute Public/private Subs, not buttons in my forms.

  But thank you for involving your self. I will come back soon as I have found a solution.
The future is Ethernet as fieldbus.

Skrevet tir. d. 09. marts 2010 kl. 18:34:52| #25

op1
op1 (11.505 point)
Hi Terry

Have found a solution. What do you think?

If If KvVeiingAvsl = 1 Then
LoggVektverdi_Click  ' Executes this sub.
End if

Has to be placed under: Private Sub Form_Timer()

Skrevet tir. d. 09. marts 2010 kl. 19:28:56| #26

terry
terry (244.617 point)
Nice :o)

Actualy close to what I've been trying to get to :o)

Skrevet tir. d. 09. marts 2010 kl. 20:21:41| #27

op1
op1 (11.505 point)
Closing Who deserves the points?

Skrevet tir. d. 09. marts 2010 kl. 20:25:49| #28

op1
op1 (11.505 point)
Terry should have because of his helpfulness.
Oh. I did something wrong here. I gave the points to my self.

Skrevet tir. d. 09. marts 2010 kl. 20:48:24| #29

terry
terry (244.617 point)
No problem, I have lots already. So many I dont know what to do with them. What can you do with them?? :o)

Skrevet ons. d. 10. marts 2010 kl. 08:31:16| #30

op1
op1 (11.505 point)
It is probably a kind of high status having many points.
I'm not in the kategory beeing able to get many points.
Guess I'm better to ask than to answer. Have a nice day.

Skriv et indlæg




Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] [img]link til billede[/img]
Web- og emailadresser omdannes automatisk til links

Log ind

   

   

Seneste spørgsmål

Dato og Klokkeslet "Live"

Oprettet den 11. februar 2012 kl. 19.39
jmarques giver 60 point for svar | Giv et svar »

Link til et dokument

Oprettet den 10. februar 2012 kl. 14.15
omn giver 60 point for svar | Giv et svar »

Formular med flere paramtre

Oprettet den 9. februar 2012 kl. 16.48
stuegnu giver 100 point for svar | Giv et svar »

Seneste guides

Installer win 7
Den gode bruger


   




Tips & Tricks fra PC World

Teaser billede

Her er fem sjove danske websider du skal kende

Trænger dine lattermuskler til en omgang fitness på dansk? Vi viser vej til fem websider fyldt med humor og vanvittig satire.


Anmeldelser fra PC World

Teaser billede

Test: Denne super-tablet er iPads hårdeste konkurrent

Eee Pad Transformer Prime er frygtindgydende med sin quadcore processor og evne til at trylle sig om til bærbar. Apple bør kigge i bagspejlet, for Asus' tablet-pc kommer buldrende - og gør det...


Seneste blogindlæg

Teaser billede

Tvangslukke spørgsmål: Hvad er den bedste løsning?

Hej Vi har mange åbne spørgsmål på Eksperten. Vi ville gerne tvangslukke dem - så et spørgsmål efter f.eks. 6 måneder lukkes. Men der er et par uklarheder som ville være gode at få lidt input til:...


Nyheder fra PC World

Teaser billede

Nu kan du snart hente Windows 8

Den nye offentlige betaversion af Windows 8 er klar i denne måned.


Nyheder fra Computerworld

Teaser billede

Måske snart slut med Androids helt store problem

Android-platformen har længe været plaget af et særligt problem. Men måske er problemet nu ved at være elimineret.


Kurser
Samarbejdspartnere

Udgiver · © 2012 IDG Danmark A/S · Hørkær 18 · 2730 Herlev · Tlf.: 77 300 300 · Fax: 77 300 301 · Brug af personoplysninger