How to Implement Data Communication Using Modbus RTU? (part 2)

Jan 12

How to Implement Data Communication Using Modbus RTU? (part 2)

Tweet So how to arrange data exchange through Modbus RTU?  Answering multiple requests and inspired by @burgua, @maxmaxmax and other people I have finally decided to write down a second part of the manual šŸ™‚ In order to start up data exchange protocol, it is required to implement it both on master (in our case PC) and slave (board RS-485 with port). All this will work with RS-485 ā€“ USB adapter. Let’s have a look at Modbus RTU configuration implementation, where PC is a master (i.e. query sender) and a board is a slave (query responding unit). For the very beginning, one should define address chart to be completely matching address map set in the controller which we are going to use: Click to toggle codeblock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 namespace Modbus {     public enum ModbusMap     {         ADR_STAT = 0,         ADR_ADC_STATUS = 1,         ADR_ADC_RESULT = 2,         ADR_ADC_ENG_VALUES = 12,         ADR_TIME = 22,         ADR_BINR_STATE = 25,         ADR_BINR_ATTEMPTNUM = 26,         ADR_STATUS_IOBSM = 27,         ADR_DIVISOR_COUNTER = 28,         ADR_TIME_SCALE = 29,         ADR_GSK_RES = 55,         ADR_OSK_RES = 83,         ADR_CMD = 111,         ADR_NAV_TASK_STATE = 112,         ADR_NAV_TASK_CORRECT_ORB_INDEX = 113,         ADR_NAV_TASK_CORRECT_ORB_INDEX_ITER = 114,         ADR_COUNT_GPS_DATA = 115,         ADR_COUNT_GPS_TASK = 116,         ADR_FIRST_INDEX_GPS_TASK = 117,         ADR_IS_CYCLE_READ_MODE = 118,         ADR_STORE_DIVISOR = 119     } } namespace Modbus { public enum ModbusMap { ADR_STAT = 0, ADR_ADC_STATUS = 1, ADR_ADC_RESULT = 2, ADR_ADC_ENG_VALUES = 12, ADR_TIME = 22, ADR_BINR_STATE = 25, ADR_BINR_ATTEMPTNUM = 26, ADR_STATUS_IOBSM = 27, ADR_DIVISOR_COUNTER = 28, ADR_TIME_SCALE = 29, ADR_GSK_RES = 55, ADR_OSK_RES = 83, ADR_CMD = 111, ADR_NAV_TASK_STATE = 112, ADR_NAV_TASK_CORRECT_ORB_INDEX = 113, ADR_NAV_TASK_CORRECT_ORB_INDEX_ITER = 114, ADR_COUNT_GPS_DATA...

Read More

How to Implement Data Communication Using Modbus RTU? (part 1)

Mar 19

How to Implement Data Communication Using Modbus RTU? (part 1)

Tweet Not so long ago, I was engaged in the MC programming (in the framework of the work on the nanosatellite), in particular, I implemented a communication between devices by different protocols. So, where do we start? When it is necessary to solve this kind of problem, first of all, you should choose (if there are “hardware” restrictions, it means that the choice is partly made for us): data communication type (synchronous, asynchronous); interface (RS-232, RS-422, RS-485, USB, Bluetooth, etc.); protocol (WAKE, Modbus, etc.). To make the right choice, you need to take into account the scope, speed and signal transmission distance limits and other characteristics. One of my tasks was to implement a data communication between a computer and the STM32F105 MC on the existing board. On the interface board, there was the RS-485 for asynchronous serial data communication, which allows implementing connection of up to 32 devices at the same time, has a speed of 30Ā Mbit/s and a transmission distance of 1Ā 200Ā m (seeĀ Table 1). Parameter RS-485 Data communication type Differential Maximum number of receivers 32 Maximum cable length 1200 m Maximum transmission rate 30 MBit/sec Output voltage -7…+12 V Receiver sensitivity Ā±200 mV Table 1. RS-485 interface parameters In principle, it is possible to implement a data communication without a protocol, but in this way, nobody guaranteeĀ data integrity and timely delivery, so a common practice is to use specialized protocols. Data communication protocol is a set of agreements of a logic level interface that define a data communication between different programs. These agreements define a uniform method for transmitting messages and error handling in the interaction of software of spaced apart devices, connected by one or another interface.Ā A standardized data communication protocol also enables to develop interfaces (now at the physical level), which are not tied to a particular hardware platform and manufacturer (e.g., USB, Bluetooth). Communication protocols generally operate on the “master-slave”Ā principle. A master initiates a communication and sends a request to slave devices (slaves), and slave devices respond (or do not respond) to requests according to the address in a package. There are many protocols, but one of the most common is Modbus. The Modbus protocol was established many years ago but is still very...

Read More

IT Jam 2012 Report

Sep 20

IT Jam 2012 Report

Tweet September 1 is not only the day of knowledge, peonies, and teachers, but it is also a day of fun for more than 3,000 IT specialists in the NSC “Olimpiiskii“. Truly speaking, I have not seen anywhere else such a long queue for registration. When registering, in addition to cute notebooks-pens-markers-pins-magnets, you could also get a card of the first off-line social network, RFIDLE. The card is linked to my Facebook page, and with the help of it, I can give likes, add friends and upload photos using special terminals. The idea is excellent, but unfortunately, terminals often denied. In a couple of days, RFIDLE sent me a questionnaire by mail, and it turned out that we became participants of a beta testing, so let’s hope that developers are already fixing the system. ā€œWe are here to celebrate!ā€ said IT Jam slogans. On two stages (under the titles ā€œNew ideas and technologiesā€ and ā€œFrom vision to implementationā€) technical gurus told stories of their success in a simple and humorous way. Apart from Ukrainian speakers Max Istchenko (founder of the well-known DOU Ukrainian developer community) and Michael Zavileiskii (General Manager of the DataArt company), there were also foreign guests: Christopher Marsh (technical developer at AKQA), Greg Young (independent consultant and entrepreneur), Torben Maygaard (Ciklum founder) and others. Companies raffled off licenses (I, for example, wanted to win a license from JetBrains for Resharper, but alas, failed to), cups, T-shirts, Lego; held competitions and polls (DataArt gave everybody beans in bags for voting; some members even took them home, maybe in order to plant). But I was lucky enough to win a 20% discount on the preparation for the Microsoft certification in the training center, which is also good. Around the pavilion, there were Chucks Norris with jokes and a different stuff for entertainment. But the most important thing was going on in the community spots, where developers of different areas were communicating and exchanging contacts. Ironically, I almost missed the .NET lectures but had a great time with the guys from Podcasting. It was very entertaining to learn from the ā€œinsideā€ how to create podcasts, as I often listen to Mikhail Marchenko and to his podcast ā€œFrankly about IT...

Read More

Knowledge Day with IT-Jam 2012

Jul 30

Knowledge Day with IT-Jam 2012

Tweet The first of September. Young children go to school with large bags and flowers, and big kids are going to the most anticipated in the Kiev IT-event of the fall, but without bags and, of course, no flowers. This year, we will communicate in 5 areas to suit all tastes: .NET, QA, Web Development, and the Mobile Java (hope for Java and .NET pavilions will be located far enough away from each other, given the perennial holy warsĀ of developers). By the way, on IT Jam site are presented various Community Spots (.NET, IOS, Agile, etc.) and registration still open. Well, see you on September 1 in NSK “Olympic”! And let everything be in the jam šŸ™‚...

Read More

Competition for Programmers Organized by the ā€œInfopulseā€

Jun 20

Competition for Programmers Organized by the ā€œInfopulseā€

Tweet A few days ago Iā€™ve participated in the competition for programmers organized by the “Infopulse”, which was held in honor the company being at Habrahabr for one year. There were very interesting puzzles for fans of “tuning up” mind after work. It was necessary to determine the programming language in 6 tasks, find a line with an error, correct it and justify your correction. The one, who sent correct answers first, was given tickets for the match Sweden-France, a part of our Euro 2012. The first tasks were only for a start, later they got more difficult, and I struggled for a very long time with the last one. It was an assembler for the DCPU-16, which could only be debugged using an emulator. Oh, the employees of the ā€œInfopulseā€ company! They have really puzzled a girl šŸ˜‰ Result: I didn’t win, @MarkAblov was the first to send the right answers, but the competition was informative....

Read More

.NET Saturday in SkyPoint

May 27

.NET Saturday in SkyPoint

Tweet Iā€™ve visited the .NET Saturday organized by the Ciklum Company on May 26. I’ll tell you a little bit about my impressions. The program was really nice, exactly as the organizers warned. There were: Eugene Zharkov ā€“ ā€œWindows 8 Metro App: JavaScript Dark Sideā€; Petr Afanasiev ā€“ ā€œPerfect API: ASP.NET Web API inside!ā€; Sergey Koshel ā€“ ā€œWhen optimistic lock is not a case (.NET/SQL)ā€; Vitaliy Domnikov ā€“ ā€œF# – To Iterate is Human, to Recurse, Divineā€; Alexandr Ivanitskiy ā€“ ā€œXAML – a markup language for WPF, Silverlight and Metro applicationsā€. In addition to the main screen, there was an additional screen installed for tweets with the CiklumNETĀ hashtag, which perfectly entertained the audience. It is a pity that I couldnā€™t attend all the lectures, but Vitali’s lecture on F# made a great impression on me, however, the lecture by Alexander was saved only by trolls twitting about cups, women, and dresses. So, from now on, I will visit meetups in Ciklum more frequently. Oh yes, I almost forgot. I promised to try F# and finally did it.Ā The program is the calculation of factorial of the n number. Click to toggle codeblock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // Create function for calculating factorial let rec factorial n = match n with | 0 -> 1 | _ -> n * factorial (n - 1)   // using System open System   Console.Write(@"Enter n = ") let n = Convert.ToInt32(Console.ReadLine())   // Calculate and write result let result = factorial n Console.Write(@"Result = ") Console.WriteLine(result) // Create function for calculating factorial let rec factorial n = match n with | 0 -> 1 | _ -> n * factorial (n - 1) // using System open System Console.Write(@"Enter n = ") let n = Convert.ToInt32(Console.ReadLine()) // Calculate and write result let result = factorial n Console.Write(@"Result = ") Console.WriteLine(result) It is really possible to write programs on this functional language quite quickly and efficiently if you want to work with math functions. Dark side is the same: you have to think...

Read More
We #StandWithUkraine.
Learn how you can help too!

#Stand­With­Ukraine

We don't know how long the war will last. But what we do know is that we can't stand aside and watch.

The fastest way you can help too is to support Ukraine financially. The National Bank of Ukraine (NBU) has opened a multi-currency account for that purpose. Learn more

This account accepts donations in US, Canadian and Australian dollars, euros, British pounds, Swiss francs, yuan and yen.

UA823000010000032302338301027

Also accepting cryptocurrency donations ā€“ the fastest way to help. Learn more

BTC ā€“ 357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P

ETH, USDT (ERC-20) ā€“ 0x165CD37b4C644C2921454429E7F9358d18A45e14

If you want to volunteer in the army of Ukraine and help with deeds, then here are specific instructions how to do this: Learn more

Spread the word!