Previous Thread
Next Thread
Print Thread
Rate This Thread
Hop To
#4597924 - 04/25/22 10:42 AM Can TARGET software report axes values?  
Joined: Apr 2022
Posts: 5
grandpa_pilot Offline
Junior Member
grandpa_pilot  Offline
Junior Member

Joined: Apr 2022
Posts: 5
Hi All,

This is first post as a newly joined member. I have recently started using the TARGET software. A huge learning curve obviously lies ahead. Thank you for all the valuable information posted by some very knowledgeable users.

Now my question: Through the use of a script I can get TARGET to play a sound, and do many other things. Great! But, how do I report the Direct axes values to my Target console?

Similar to what the Event Analyzer does. See attached image. I have no need to report values to a text file. Not useful to me.

Any pointers by other members appreciated.

Attached Files target_console.gif
Inline advert (2nd and 3rd post)

#4597937 - 04/25/22 01:32 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Jul 2016
Posts: 61
Drakoz Offline
Junior Member
Drakoz  Offline
Junior Member

Joined: Jul 2016
Posts: 61
You can report the axis value of a device using something along the lines of the following:

Code
int position;
position = Joystick[JOYX];
printf("Position = %d]\xa", position);


In the example, Joystick can be any of the names for a compatible Thrustmaster device such as &Joystick, &Throttle, &HCougar, &T16000, etc. Just remove the &. Joystick[], or HCougar[], etc. is just an array of integer. The variable JOYX is an index value (an integer) that points to the part of the Joystick[] array which contains the current position of the Warthog Joystick X axis. You can see the allowed values of the index in the defines.tmh file (which is in the scripts folder under C:\Program Files\Thurstmaster\TARGET\Scripts or something like that (sorry I forget the exact location - not on my desktop PC right now).

printf() in TARGET works very similar to printf() in C language, but there are some oddities. For example, to create a newline, you can't use \n, but instead must use an escaped ASCII code such as \xa as I show in my example above. Use \x9 for a tab for example. The 9 and a are the ASCII codes for a tab and new line respectively.

You can put code like the above example in a EXEC() command and trigger it using a button press, or you can put it in the EventHandle() routine at the bottom of your .tmc file. Use if statements or other code to decide if and when you want to print out data when putting code in the EventHandle(). Otherwise, it will print something out ever time any axis movement or button press occurs on any TARGET controlled device. There should be numerous examples of doing that kind of thing in other topics on this forum. Or ask specific questions here and I or others can help you out.

If you want to see complete examples of complex TARGET programming, check out the target.tmh file (found in the same place where you find the defines.tmh file) which gives a lot of clues to the inner workings of TARGET, or check out my Train Sim World TARGET script at the link below. I don't assume you care about Train Sim World, but my TSW script has examples of all kinds of methods of reading axis data, manipulating it and printing it to the console. The script converts axis positions to keyboard presses. TSW doesn't support using a joystick, so I created this script to press keys depending on the movement of various axes. You can run it without running TSW. Just run the Thurstmaster Event tool (the one that shows you keyboard press events) to show the keyboard presses, and watch the info the script prints into the TARGET console for an example of printing data to the console.

Most the examples you probably care about can be found in the Drakoz_TrainSimWorld.tmh file. Look for either KeyAxisDirZone(), or KeyAxisDirNotch(). These two routines read the axis position, convert it to percentage (0 to 100%) and then act upon the position by using the ActKey() command in ActKeyDelay() to press keyboard keys.

https://forums.dovetailgames.com/th...warthog-throttle-saitek-tq-profile.3634/

I hope that helps.

#4598056 - 04/26/22 01:42 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Apr 2022
Posts: 5
grandpa_pilot Offline
Junior Member
grandpa_pilot  Offline
Junior Member

Joined: Apr 2022
Posts: 5
Hi Drakoz, thank you for responding. Your explanation is 100%. It will most certainly help me and other users. Thank you also for your willingness to assist myself and other TARGET users.

Would really like to see your Train Sim World TARGET script, however, when I clicked on the link "Download here - V4.3.1" nothing happened. I shall try again another day. Cheers!

#4598081 - 04/26/22 06:04 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Jul 2016
Posts: 61
Drakoz Offline
Junior Member
Drakoz  Offline
Junior Member

Joined: Jul 2016
Posts: 61
Regarding the TSW script, if it doesn't download, yes, try again later. My server goes down sometimes. I need to replace the hardware. Sorry for the trouble.

#4598836 - 05/05/22 01:47 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Apr 2022
Posts: 5
grandpa_pilot Offline
Junior Member
grandpa_pilot  Offline
Junior Member

Joined: Apr 2022
Posts: 5
Hi All, this is a quick question as I'm still learning the TARGET software. I have been successful in reporting axis positions to the console thanks to the help shown further above. My next attempt is to export the same axis values from TARGET to an external application - most probably a C++ application.

I am aware that TARGET can receive external input i.e. receive data from an external application via a TCP port, but I would like to attempt the reverse. Hope I explained this okay.

Is this at all possible with TARGET?

#4598897 - 05/05/22 10:47 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Jul 2016
Posts: 61
Drakoz Offline
Junior Member
Drakoz  Offline
Junior Member

Joined: Jul 2016
Posts: 61
Yes, TCP ports are bi-directional. Remember, as I mentioned, these are network ports. So the code to send data to/from a TCP port using TARGET is very similar to the code you would use to send/receive data via an Ethernet or WiFi TCP port. Or more correctly, TCP is a protocol on top if IP (hence the term TCP/IP). IP is a protocol on top of the hardware interface (Ethernet, WiFi, Bluetooth, etc.). So the TCP protocol doesn't understand what hardware it is communicating on. It just understands that a message is to be send or received from a TCP port, and it uses an IP address to do that. For communication between two applications on the same computer, the IP address is 127.0.0.1, and you define the TCP port when you set up the channel (e.g. 127.0.0.1:51850). Many TCP ports are pre-defined such as HTML uses :8080, and email often uses :993 to receive email, and :25 to send mail.

These ports are bi-directional.

To learn more, look at examples of sending TCP packets using C++ or C in general from Microsoft's developer sites. There are probably a few examples doing bi-directional communication with various server types like HTML, but also generic communication where you define the format of the packet yourself. And since this is TCP, it is all part of IEEE 802.11, an term you may have heard about.

Then to translate all this into TARGET, you have to load the Windows library (.DLL) that deals with TCP packet communication and then you will have access to the same library routines in TARGET used by the C language examples you find at Microsoft's web site or elsewhere.

A few additional comments:

The two comands you need from TARGET to make this work are:

From the TARGET sys.tmh file:
Use this to load the Windows LIbrary (.DLL) for the TDP protocol. I believe this works similar to the Windows LoadLibrary() command. But Thrustmaster had to include their own instead of using the Windows version.

Code
int LoadLibrary(alias filename){}


From the target hid.tmh file:
Use this command to create the TCP or UDP port, but you have to do some other commands to finish setting up the port.

Code
//Creates a server on the specified port to process external data
//port      - the port number used by the server
//useUDP    - 0(default) to use TCP protocol, 1 for UDP datagrams
//interface - 0(default) to install the server on the local interfaces,
//            a string IP address to use the corresponding interface only
//NOTE:	TCP needs 2Bytes at the start of each frame indicating the size of the packet ( 2 + size of data that will follow)
//			this information will not be passed to the callback, but it is needed to separate the frame from the stream
//			(the size info can be added to the data buffer or with a separate call, before sending the data)
//		UDP sends the whole packet in one chunk, no extra size information is needed
//		maximum data size is limited to 4096Bytes
int InitSocketServer(int port, int useUDP=0, int interface=0){}



These protocols can also due UDP. UDP is a simpler method of communication. Both work on top of IP.

Using TCP should work very similar in TARGET as it works in the Windows programming examples, but in TARGET, it must work within the constraints of TARGET. For example, TARGET does not understand the concept of a string. There is type char (a single byte), but strings as defined normally in C do not work in TARGET. Instead, you must use the &name convetion. Like throughout TARGET, we say &Joystick or &HCougar. It is too much to get into that in this emai, but in simple explanation, if you want to use strings, you must allocate memory and reference them with pointers (similar to C), but & is not a pointer in the normal sense. It is called a type alias. The alias is kind of like a C pointer, but & and * aren't the same. I can help with this more later, but review how & is used in the target.tmh file. That is where I figured it all out. If you don't need to send strings, but numbers or char is good enough, you can avoid all that mess with &. Or you might be able to use printf() to send text strings through TCP the same way we use it to print to the console, or print to a file.

This is all getting to somewhat deep understanding of C programming, not novice level stuff. Not sure your level of understanding, but the more you understand about C (or C++), the easier this will be. Don't be afraid to dive in.

#4599147 - 05/09/22 01:31 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Apr 2022
Posts: 5
grandpa_pilot Offline
Junior Member
grandpa_pilot  Offline
Junior Member

Joined: Apr 2022
Posts: 5
Hi Drakoz, thank you for all this information. You are a generous and helpful person. I've taken note of what you've mentioned about sending strings. Fortunately, my first goal is to send only integer numbers ranging 0 to 100. Taken your advice and looking at examples on how to send TCP packets.

#4599178 - 05/09/22 05:36 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Jul 2016
Posts: 61
Drakoz Offline
Junior Member
Drakoz  Offline
Junior Member

Joined: Jul 2016
Posts: 61
Glad I can help. I would love to see what you figure out.

#4599665 - 05/16/22 01:38 PM Re: Can TARGET software report axes values? [Re: grandpa_pilot]  
Joined: Apr 2022
Posts: 5
grandpa_pilot Offline
Junior Member
grandpa_pilot  Offline
Junior Member

Joined: Apr 2022
Posts: 5
Hi Drakoz, you've gathered by now that I am a complete novice. Based on your explanation re TCP ports being bi-directional, I shall need to use a function in my TM script to create a TCP client socket which will connect to a server listener socket, enabling me to export integer values (0-100) (these are throttle axis values constantly changing as I move my throttle) from within my TM script. I just need to establish that I am on the right track and that the flow of information is from Client to Server? Many thanks.


Moderated by  RacerGT 

Quick Search
Recent Articles
Support SimHQ

If you shop on Amazon use this Amazon link to support SimHQ
.
Social


Recent Topics
Actors portraying US Presidents
by PanzerMeyer. 04/19/24 12:19 PM
Dickey Betts was 80
by Rick_Rawlings. 04/19/24 01:11 AM
Exodus
by RedOneAlpha. 04/18/24 05:46 PM
Grumman Wildcat unique landing gear
by Coot. 04/17/24 03:54 PM
Peter Higgs was 94
by Rick_Rawlings. 04/17/24 12:28 AM
Whitey Herzog was 92
by F4UDash4. 04/16/24 04:41 PM
Anyone can tell me what this is?
by NoFlyBoy. 04/16/24 04:10 PM
10 Years ago MV Sewol
by wormfood. 04/15/24 08:25 PM
Pride Of Jenni race win
by NoFlyBoy. 04/15/24 12:22 AM
Copyright 1997-2016, SimHQ Inc. All Rights Reserved.

Powered by UBB.threads™ PHP Forum Software 7.6.0