|
I am trying to make a stepper controller. Several Windows CNC controllers, logic analyzers and oscilloscope type program allow you to choose an update rate. They are in the 25kHz - 100kHz rate. I was wondering how they do this?
There is this article Stopwatch - a High-Resolution code timer class[^] but I don't know how you could use this to control the rate.
|
|
|
|
|
You can't do that [ADDED] in a meaningful way [/ADDED] with a [ADDED] Windows [/ADDED] PC. At best it will work some of the time; and when the net result is a physical motion it will be really dangerous for people or animals in the vicinity.
The proper way to do that is to have external logic that generates the required steps, and takes higher-level commands from the PC, at a much lower frequency. So the PC could say move to X,Y using a ramp up, a maximum speed and a ramp down, and the external logic would do all that autonomously in a couple of seconds. The safety precautions (micro-switches aborting a motion when a safety limit gets crossed] should also work inside the external logic, without any PC intervention at all.
modified on Sunday, November 29, 2009 2:42 PM
|
|
|
|
|
Luc Pattyn wrote: You can't do that with a PC
And why not? AFAIK only Windows is at fault here, in DOS you could just steal the whole machine for yourself (disable interrupts etc)
|
|
|
|
|
Sure, my statement could use some refinement; if you're willing to use all of a PC's hardware then you can do it; I could even do it with Windows, except the users won't be happy with it any more; just install a highest priority driver and let everything else come to a standstill.
However it does not make sense, you need external hardware anyway (a H-bridge, a power supply, ...), so why not do it the proper way and include a little micro-controller?
|
|
|
|
|
True, true, I was just being a pedantic bitch
|
|
|
|
|
Nope. You were right, my statement wasn't correct, I've fixed it. Thanks.
|
|
|
|
|
harold aptroot wrote: AFAIK only Windows is at fault here
Windows is a shared system, not only between users, but between apps as well. Shutting off interrupts just isn't possible. You simply cannot execute code on a fixed schedule at that rate and accuracy.
harold aptroot wrote: in DOS you could just steal the whole machine for yourself (disable interrupts etc)
DOS DOES steal the entire machine for itself, and (on the surface) only does one thing at a time.
|
|
|
|
|
Why does it sound like you're arguing when you're agreeing with me?
|
|
|
|
|
isn't that exactly what you did earlier in this thread?
|
|
|
|
|
I guess it is
|
|
|
|
|
I just got a new job doing (gak!) VB, and I'm going through the existing code base trying to get my bearings. I've run across something that I'm not sure I agree with.
They have a class which has a property that contains about 60 lines of code, and this code runs through some financial calculations to come up with a value that is returned. I guess one good thing is that no methods or data is accessed that exists outside this class.
I've always been of the opinion that a property shouldn't perform anything more than simple get/set functionality, and extra processing should be handled in a method. Indeed, I've been bitten by this in the past, so I take extreme steps to avoid it now.
What do you guys think?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I haven't done such things myself, and I wouldn't do it.
Most often a getter simply returns a private data member's value, whereas a setter may be more complex, as it may have to update the internal state of the entire object, not just the one corresponding data member.
A calculation deserves a method. However IMO it is just a matter of style, I know of no technical reason to prefer a method over a getter property.
And that would be the same in most .NET languages...
|
|
|
|
|
Luc Pattyn wrote: I know of no technical reason to prefer a method over a getter property.
Not a technical, but empirical; a method would imply an action of some sort, to retrieve a value. A property would imply that there's a value to be read.
I are Troll
|
|
|
|
|
Yes, I agree, to me a getter typically returns the value of an internal variable, however there isn't a hard border line for me. I would not mind getting property "Area" for a Rectangle object (even if setting Area wouldn't make sense); and I would try and avoid database accesses in a property. Having a method name with a verb in there should indicate real actions, whereas property names are supposed to be nouns, without verb part.
|
|
|
|
|
I disagree, I don't have any problem with code for a property. I think of properties of a class as a 'logical' view to it, that is more or less independent of the actual implementation. Where I have to agree with you is that this raises the question if a property is 'physical' or 'logical'.
Rozis
|
|
|
|
|
I don't either - generally, but this one calls methods in the class, and as far as I'm concerned, that's a no-no because it could throw an exception. IMHO, setting/getting properties should NOT be able to throw exceptions because they should always contain valid data.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I would agree; keep the property simple.
You are dealing with VB, I'm sure you will find much worse coding.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
John Simmons / outlaw programmer wrote: property that contains about 60 lines of code...
...must be changed to method. That is what I would have done. Apart from little bit code like increment/decrement or any conversion/casting if needed, I never write anything in properties.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
You want interface as lean as possible. If you need additional functions than they should be private functions in VB or static functions in your source files in C/C++. 60 lines is not that large of a function.
|
|
|
|
|
I agree with what's been said here, in summary:
get should do be limited to: minimal computation involving readily available data
set should do be limited to: minimal computation involved to transfer data to a readily available store and any relevant event handler notification.
There's nothing worse than expanding this in Visual Studio and having to wait for 5 minutes while it evaluates a bunch of properties that you likely don't care about!
|
|
|
|
|
hi i need help to how wait the process finish.
for example.
pc : is a string "contain ip pc"
position : is integer "contain index number to know how item will change the imageindex of current item in other listviewitem1
for each item as listviewitem in listview1.items
pc = item.ToolTipText
position = item.index
ping_to_host() ' here i have a sub created to ping ip and in sub he change the imageindex in the other listview ( for exmaple : 0 is "off" and 1 is "on" )
next
OK the problem is not here , the problem is when he get de position and pc name he go to the ping_to_host() sub .
this process is very fast for ping process can complete of the first ip recepted.
when he are pinging to ip "1" the process can't complete because don't have time for complete .
how i can set a time or wait to ping process complete for can jump for next item.
SORRY , SO LONG TIME NO SPEAK ENGLISH
|
|
|
|
|
Put the ping code into a thread and join the thread... That should wait for the thread to finish before processing continues.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
i don't know how to insert.
the button to shearch is here :
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim posicaoatual As String
Dim itemselecionado As String
Dim t As Thread
For Each items As ListViewItem In lstrefresh.Items
items.Selected = True
For Each selecionado As ListViewItem In lstrefresh.SelectedItems
Main.PosicaoEstacaoNoList = selecionado.Index
Main.estacaoSelected = selecionado.SubItems.Item(2).Text
Control.Ping_to_host()
't = New Thread(AddressOf processo.Ping_to_host)
' MessageBox.Show(Main.estacaoSelected & vbCrLf & Main.PosicaoEstacaoNoList)
't.Start()
Next
Next
End Sub
here i have the ping code :
Public Sub Ping_to_host()
Main.RichTextBox1.Clear()
Dim vez As String = 3
'Dim host As String = Main.estacaoSelected
Dim ip As String = Main.estacaoSelected
Dim ans, ans2
Dim i As Integer
'ans = InputBox("Digite o Endereço desejado", "Host", "www.google.com.br")
ans = ip
If ans = "" Then
Exit Sub
Else
host = ans.ToString
'ans2 = InputBox("Pro favor digite a quantidade de vezes para pingar", "Ping count", "1")
ans2 = vez
If ans2 = "" Then
Exit Sub
Else
vezes = ans2.ToString
' For i = 0 To System.Convert.ToInt32(vezes.Text)
' For i = 1 To System.Convert.ToInt32(vezes.Text)
Me.Timer3.Enabled = True
'Me.Timer3.Start()
'Next
End If
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim lstText As String
Dim i As Integer
'Me.Timer3.Enabled = True
'Me.Timer3.Start()
For i = 1 To System.Convert.ToInt16(vezes)
Try
If My.Computer.Network.Ping(Me.host) Then
'MsgBox("Ping successfull", MsgBoxStyle.Information, "Successfull")
lstText = Now() & " --- " & host & " -- " & "Ping OK" & vbCrLf
' MsgBox("oi")
Main.RichTextBox1.Text = LTrim(Main.RichTextBox1.Text) & lstText
'If RefreshPC.refreshPC_tipo = "RefreshAll" Then
' RefreshPC.status_ping = "ON"
'End If
stat = "on"
Else
'MsgBox("Ping unsuccessfull", MsgBoxStyle.Critical, "Unsuccessfull")
lstText = Now() & " --- " & host & " -- " & "Ping error" & vbCrLf
Main.lstestacoes.Items.Item(Main.PosicaoEstacaoNoList).ImageIndex = 1
Main.RichTextBox1.Text = LTrim(Main.RichTextBox1.Text) & lstText
End If
Catch ex As Exception
lstText = Now() & " " & host & " -- " & "Ping error" & vbCrLf
Main.RichTextBox1.Text = LTrim(Main.RichTextBox1.Text) & lstText
Main.lstestacoes.Items.Item(Main.PosicaoEstacaoNoList).ImageIndex = 1
End Try
Next
Main.RichTextBox1.Text = LTrim(Main.RichTextBox1.Text) & "Done..."
Me.Timer3.Enabled = False
RaiseEvent ThreadCompleta(stat)
'Me.Timer3.Stop()
End Sub
with need more say me please...
|
|
|
|
|
i resolved this problem using "While"
|
|
|
|
|
Hi,
Vista 32 bit machine SP2
I am using VS 2010 beta 2 on this test machine, just installed the MS SDK for 2010 beta 2 today. I am unable to find any way to get a Visual Studio command prompt to launch Ngen. It does not appear in the places MS's current on-line documentation says it should appear. It just ain't there.
Doing a search for "ngen.exe," I find nine copies of it going back to 2006, and what appear to be four identical copies of it (99k in size) in various strange folders with what look GUID's in their titles.
Sure I can get a command prompt of the usual sort the usual ways, but I am under the impression there is a special command prompt for Visual Studio : perhaps that's way off.
Appreciate any advice, best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|