martin Posted March 30, 2012 Posted March 30, 2012 A really big improvement Nikosliapis, I like your new version and I think it is much more versatile now. Do you plan to be able to make the program update the Arduino source code? I think that there shouldn't be a line saying "END USER COMMENT" after the code because it makes the code look like it's part of the comment. That line could just be omitted for me. But I think the "//RULE 1 START" and "//RULE 1 END" are correct. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted March 30, 2012 Author Posted March 30, 2012 (edited) martin Do you plan to be able to make the program update the Arduino source code?What i plan to do is to add the ability to "import" directly from arduino code (which i think is the most difficult task ) so that the user will be able to make any changes he wants and then regenerate the changed arduino code. My objective is to make the program closer to what you've described here: 1. I start with an idea of what I want and how I will achieve it. Of course things will change as I go along. 2. I begin with your NAG programmer and I create a few rules. This gives me some code. 3. I work on the code adding things which I want. Maybe a wifi shield or a display. Maybe I just add some comments but it could be anything. 4. I decide that I need some more rules for inputs, or that I need to change a rule so I go back to your programmer. 5. I create the new rule or ciorrect an old one by editing the saved project I think that there shouldn't be a line saying "END USER COMMENT"At first this line was not generated, but after a few test i've made, i realised that if you choose not to "mark" the arduino code with the number of rule. then all the following code would look like belonging in the above user comment. Such a situation is show below: As you can see i commented only on the second rule but in the generated code looks like i commented for the next rule as well. Anyway things like that are just a matter of opinion . Looking forward for more recomentations. Thank you again. Edited March 30, 2012 by nikosliapis Coding can be fun when you do it your own.
martin Posted March 31, 2012 Posted March 31, 2012 At first this line was not generated, but after a few test i've made, i realised that if you choose not to "mark" the arduino code......Yes, that's a good point. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted April 2, 2012 Author Posted April 2, 2012 (edited) New version is released. Most importand feature added is the ability to import an Arduino code file for the user to edit. (Of course the imported file must have been previously generated from my program) As always the latest version is on the first post. I'm thinking to make a "pseudo" simulator so that the user can test the apllied rules before generating the code. Don't have an idea how to do it but i'll give it a try. Edited April 2, 2012 by nikosliapis Coding can be fun when you do it your own.
martin Posted April 2, 2012 Posted April 2, 2012 (edited) If I generate code and save, and then import I get duplicated rules. If I import again I get triplicated rules. EDIT:It's a bit worrying when there are errors or warnings given when you run a script.<nitpick>My recommendation is that if there are global variables then these should be declared at the start of the script and not inside a function. If they are global then they do not really belong to the function, they belong to the whole script.This gives the following advantages:Easier to understand and maintain the scriptprevents the warningsif the function which contains the global declaration is called again, and all the gloabl elements declared are not initialized, then any set values will not get obliterated.</nitpick> Edited April 2, 2012 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted April 3, 2012 Author Posted April 3, 2012 If I generate code and save, and then import I get duplicated rules. If I import again I get triplicated rules. Sorry, forgot to clear Rules and settings before importing .Looks like i was to eager to upload this new feature that i didn't testit enough. t's a bit worrying when there are errors or warnings given when you run a scriptYou are referring to the msgboxes along the operation of the script, or to script crashes ?As for your reccomendation on global variables you are correct again. This "not so good" use of global variables is the result of my very small experience writing code in general.There are other thinks that i don't really like in my code. For example:- Many of my functions have no parameters at all- Many times i call a function from within a function- I use a lot of "if's" and "elseif's"and thinks like that.I hope that one day (following the communitys advise) i will overcome all this thinks and will be able to write "well structured" code.Also i want your opinion on a matter:In the current version when the user "imports" a file, the script "reads" the lines that are between the marks :" *** START SETTINGS GENERATED FROM NAG PROGRAMMER *** " and" *** START RULES GENERATED FROM NAG PROGRAMMER *** "If you generate the code again the script wont generate any rule or settings that is outside of these marks.You think that i should change this , and keep the lines outside of the marks as is ? Coding can be fun when you do it your own.
martin Posted April 3, 2012 Posted April 3, 2012 (edited) The "errors or warnings" that I referred to were the ones generated by the AU3Check in the scite ouput pane. EG >Running AU3Check (1.54.22.0) from:C:Program FilesAutoIt3 C:Documents and SettingsMartinLocal SettingsTempArduino Programmer V0.14.au3(124,26) : WARNING: $combo: possibly used before declaration. GUICtrlSetData ($combo[5], I think the csript should be written to eliminate these warnings. About some of your concerns. In my opinion, which is one of many, there is nothing wrong with functions without parameters, but I think that it is better to reduce the use of global variables as much as you can. Instead of using a global variable it is often better to pass a variable to a function. Ideally a function can be cut and pasted into another script and still work. A function which calls a function is fine: it's what functions are for. Using if's and else's is fine. It only becomes a problem if it makes the code hard to understand and hard to maintain and if that happens you need toi think of different ways. My view is that there are only 2 important things to worry about with writing programs. The first requirement is that it must work as required. I have never yet had a customer who has shown any interest at all in how I made the program, but plenty of "why does this .. " and " why doesn't that.." and "how do I do XYZ" when XYZ is explained clearly in the help file which they think is only to be read if they can't get me to answer the phone. The second most important thing is that you can easily change it to behave differently. That includes fixing errors. If you can do those two things then how you write it or what style you use or what languge you use are of no importance to anyone but you. I'm not sure I fully understand your last question about the marks so I'm going to play with the latest version. However I have some other things I must do first and it will be 2 days before I come back to this. Edited April 3, 2012 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted April 7, 2012 Author Posted April 7, 2012 Well, the first cut of the "pseudo" simulator is finished and uploaded. For now doesn't support analog inputs or outputs, only digital (High and Low) but i'm working on it. Of course this the first cut of the "simulator", so the code is a little rough The latest version is available on the first post ps. Martin sorry, but didn't yet correct the warnigs caused from Global variables. Coding can be fun when you do it your own.
martin Posted April 8, 2012 Posted April 8, 2012 There are only up to 2 logic states allowed and these have to be ANDed. If we want (A1 is High) OR (A2 is High) then SET A3 High then I can't see how to do it with your programmer, though that could be easily fixed. Could you make it so that we could type in rules into the inputs combo? Then you could deal with A0.A1./A3+A4 = A5 Then what about counters? Or If A4 goes High then call functionXYZ It looks to me like most logic would need to be written by hand into the source code at the moment, and changinging that could be very difficult. Currently, the main benefit of your programmer might be the easy way to set input and output types, and the setup() function code you generate. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted April 8, 2012 Author Posted April 8, 2012 (edited) There are only up to 2 logic states allowed and these have to be ANDed.If we want(A1 is High) OR (A2 is High) then SET A3 HighI've thought about these situations when i started creating the programmer. The solution that i found is thatin order to create an OR logic action the user should write 2 rules, for example:Rule 1) A1 is High then set A3 HighRule 2) A2 is high then set A3 high.Another "difficult" situation is when the user wants to AND 3 inputs to one output, for example :A1 is High AND A2 is High AND A3 is High then set A4 to High.That can be done creating the rules below:Rule 1) A1 is High AND A2 is High then set Virtual_Coil_0 to HighRule 2) Virtual_Coil_0 is High AND A3 is High then set A4 to HighThis the reason i created the Virtual_Coils in the first place.If the user wants more inputs inside the logic action then more rules must be created.Another "difficult" situation that just occured me is a bit difficult to explain (english is not my mother language) so i'll try to describe it with an example:Lets say that there is Input A1 and output O1If i write a rule : when A1 gets High then set O1 to High.Then O1 will get High when A1 gets High but it will not get Low when A1 gets Low, therefore the usershould add another rule : when A1 gets Low then set O1 to Low , Which i think is a good think because the user may want O1 tostay High no matter the A1 does.So far so good...But the problem is when input A1 is an analog input. With the programmer as it is at the momment whenthe user adds a rule : When A1 gets 867 then set O1 to HighThere is no way for the user to write a rule to get O1 Low again (only if another input A2 is set)So the first solution i'm thinking for this situation is automatically to generate another "if statement " saying:when A1 <> 867 then set O1 to LowThe second solution i'm thinking is when creating the rules in the programmer to add the "greater than" or "less than" option.For example the applied rule will be: When A1 is greater than 867 then set O1 to High,So the user will be able to add a rule :When A1 is less than 867 then set O1 to Low.At this point i ask for your experienced opinion,Which one of the above solutions you think is the better one?.Then what about counters?OrIf A4 goes High then call functionXYZI believe that counters is a feature which maybe i could add in a future version but calling and creating functions is definitely beyond my coding knowledge and skills . After all the reason i start creating the programmer was to manipulate inputs and outputs, of course this doesn't mean that i will stop trying to add more features. Edited April 8, 2012 by nikosliapis Coding can be fun when you do it your own.
martin Posted April 8, 2012 Posted April 8, 2012 To me, saying when A1 = 826 then set A2 low is a problem. The analogue input might ramp up and might not be sampled at the critical time when it is briefly at 826. So I would always try to write If A1 >= 826 then set A2 high You can then have another condition to set A2 low when A1 <= 824 then set A2 low (some hysteresis is needed to prevent A2 oscillating like mad when the value of A1 is around 826.) The problem for me with writing a complicated logical condition by breaking it into several lines and using virtual coils is that it can get more difficult than writing the code required in the source. I would also like a way to set an output which would equally set it High or Low as needed, as could be done like this for example A3 = A1 AND A2 Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted April 9, 2012 Author Posted April 9, 2012 I would also like a way to set an output which would equally set it High or Low as needed, as could be done like this for exampleA3 = A1 AND A2 Sorry but didn't understand what you mean. Please explain Coding can be fun when you do it your own.
martin Posted April 10, 2012 Posted April 10, 2012 A3 = A1 and A2 I imagine the confusion for you was that I wrote A1, A2, A3 when it would have been more sensible if I had written DI1, DI2, DO1 At the moment you would need to have When DI1 is High AND DI2 is high set DO1 high When DI1 is low set DO1 low when DI2 is low set DO1 low which is too difficult, so it is better in this case, and many others, to write straight in the source code digitalWrite(dig_out[0],digitalRead(dig_in[0]) && digitalRead(dig_in[1])); or Virtual_coil1 = digitalRead(dig_in[0]) && digitalRead(dig_in[1]); digitalWrite(dig_out[0], virtual_coil1); BTW, something is wrong with the code generation for digi_in_state. Instead of digi_in_state[1] you are producing digi_in_state[{0,0,0};] I think the way the logical states are set is too limited. When you write a program you actually think the opposite way round, or at least I do. For example, I want something to represent if a machine is in a condition where it can be told to start a cycle. So I'll think something like "if the machine has been referenced and the drives are turned on and the safety door is shut and the compressed air pressure is ok then it's ready to operate". Then I'll put that into code char machine_refOK=0; #define drives_ON digitalRead(14) #define SafetyDoorshut digitalRead(15) #define airPressureOK digitalRead(16) #define AND && int const OP_OK_to_run = 6; void loop() { digitalWrite(OP_OK_to_run, machine_refOK AND drives_ON AND SafetyDoorshut AND airPressureOK.) } Since I don't often write in C that might not be the best way. For me the benfit of a programmer like you are making would be 1. being able to define the inputs and outputs easily, which you have done. 2 Being able to give the inputs, outputs and flags meaningful names. 3. being able to write rules using the meaningful names Number 3 could be difficult to make part of the programmer. But if you can write something like my example for setting OP_OK_to_run then anyone who is dealing with an Arduino can write the code quickly. So I think the emphasis should be on helping to write the code rather than finding ways to avoid writing it which could end up restricting what can be done. Maybe some of these things are already available with Arduino tools, but I'm afraid I don't know. You should take into account that I have neither touched an Arduino nor written a single line of code for one. (Yet) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted April 13, 2012 Author Posted April 13, 2012 martinYou should take into account that I have neither touched an Arduino nor written a single line of code for one. (Yet) Amazing . All those beautifull suggestions without being an arduino programmer ?. To clear my intentions i want to say that i am not an Arduino guru either (all i've made so far is a 24x16 Led Matrix using multiplexing and a small automation for my boiler at home). I find it very difficult to program using a "C like" language (this is the reason i love Autoit ).All i wanted was to make a programmer for the ones who don't know at all how to use the "original" Arduino language, so that this people can use Arduino for simple projects regardless of their scripting knowledge. This is the reason i used simple expresions on therules (When... , Then set... etc). Following your suggestions and recomendations my programmer has allready evolved more thani could ever though posible.Anyway i'm rewriting the code from scratch (this is the reason that took me long to answer). and i think that it is possible to use namesfor each declared pin (great idea )Also in the new programmer i intend to add these features:1) add a "OR" option between the two inputs2) add a "greater than" and a "less than" option in analog inputs3) add the ability for the analog outputs to be an expression of the analog inputs. For example the output to be half the value of the input. ( don't know how it can be done but i'll figure it out)I don't want to add more input fields for each rule because1)The code of my programmer will get very complex and2)The width of the window wont fit on the screen (if i use horizontal scrollbar the user wont be able to view the hall rule at once)oops an idea just came to me. How about making each rule vertical ?. Well i'll think about it. I know i may sound borring but i must thank you again for everythink.PSI want to make a personal question, you are a programmer for profession or hobby ? Coding can be fun when you do it your own.
martin Posted April 13, 2012 Posted April 13, 2012 Your new plans sound promising, although I feel a little guilty that I'm causing you a lot of work. Do I program professionally? It's a long story but yes in a way. I don't really claim to be a programmer and I know my ability is limited and that I should do things in a better way very often. But I do try to improve and I think that in the last few years I have made some progress. I am an engineer who likes to control the movement of machines. Sometimes I design machines and the controls and write the programs to make it all work. I specialize in automated glass cutting machines, typically as used by companies which produce double glazing for example. I think that's enough about me. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Qwerty212 Posted May 5, 2012 Posted May 5, 2012 martin, sorry for the offtopic, but do you know if there is any way of sending a key stroke in the keyboard from an input in an Arduino Board?I have one of this proximity sensors:And I want that when one of this sensors recieves a HIGH level run a function inside my Autoit script (for example sending a keyboard key stroke and set a Hotkeyset in my script).Nikosliapis, writting from the scratch a script like yours just to share it with us is a loable work. Thanks a lot.
martin Posted May 5, 2012 Posted May 5, 2012 All you need is to have some code which lets you detect some condition in the Arduino board and then use Send or HotkeySet in your AutoIt script. If you need to pursue this then I think you should use the general help forum. Possibly "loable" should have been "laudable"? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
nikosliapis Posted May 18, 2012 Author Posted May 18, 2012 Here i am again (Never late than never)I've been very bussy working on the Arduino Programmer, and after several failed attempts a brand new version is almost ready(to be completely honest, whith sunny sky and high temperatures, coding in a basement is not the best think )It was really hard and time consuming to write the program again using a "well structured" code.I tried to keep the use of Global variables to minimum and make more "stand alone" functions.Of course the consept of the programmer remains the same.The new features are :1) User can assign usable names to the pins and create the rules using that names.2) Added the "greater than" and "less than" option on analog pins3) The combos for rule creation are automatically modified based on each selection4) An analog output can be declared as an expression of another analog input or output (for example output A to be half the value of input A)5) Removed the "import" option from the menu (caused many problems)6) The "test rule" option is not yet completed (but will be shortly)7) I Trully tried to add more inputs in the rule, using a vertical configuration on the rules, but failed. I haven't completed yet all the tests , but i can't wait anymore, So i'll post the new version even if it is not yet completed.In a few days, a more refined version will be available. For this reason i will not putt the new version on the first post untill it is completed.Feel free to write your first impressions.Arduino Programmer V0.20.au3 Coding can be fun when you do it your own.
Qwerty212 Posted May 18, 2012 Posted May 18, 2012 Thanks for your hard work!! I will test it tomorrow. Have a nice night
nikosliapis Posted May 20, 2012 Author Posted May 20, 2012 I've tested the new version and made the appropriate changes. The Arduino simulator is not included in this version because i plan to make it in a different script. New interface version available on first post. Waiting for your feedback. Coding can be fun when you do it your own.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now